If you want to display date and time or get system Date Time with various format or specific format then there are various type of method available in VB or VB.Net or C# code. In this post SKOTechLearn explain how to Display Date Time in Different DateTime Format in VB or Vb.Net programming.
Search Files Tips From Folders and Sub-Folders in VB.Net Programming.
First, you have to know that, In programming you can use Date Time Formatting with two way:
So, let's see the examples which can be use to format predefined type in VB6, VB.Net and C# code:
Step by Step to Design Menu and Sub-Menu with Settings in VB6.0.
VB6.0:
VB.Net :
This will show the following output:Search Files Tips From Folders and Sub-Folders in VB.Net Programming.
First, you have to know that, In programming you can use Date Time Formatting with two way:
- Predefined Format method
- User-defined Format method
(1) Predefined Format Method:
Following details and code will describe, how these method will work to show predefined DateTime Format. Let's follow the following Table:Predefined Format Method | Uses |
---|---|
Now | VB6.0, VB.Net |
Date | |
Time | VB6.0 |
Format (Now, "Short date") | VB6.0, VB.Net |
Format (Now, "Long Date") | |
Format (Now, "General date") | |
Format (Now, "Short Time") | |
Format (Now, "Long Time") | |
Today | VB.Net |
TimeOfDay | |
DateTime.Now.ToString() | C#, VB.Net |
DateTime.Today.ToString() | |
DateTime.Now.TimeOfDay.ToString() | |
DateTime.Now.ToShortDateString() | |
DateTime.Now.ToLongDateString() | |
DateTime.Now.ToLocalTime().ToString() | |
DateTime.Now.ToShortTimeString() | |
DateTime.Now.ToLongTimeString() |
So, let's see the examples which can be use to format predefined type in VB6, VB.Net and C# code:
Step by Step to Design Menu and Sub-Menu with Settings in VB6.0.
VB6.0:
Private Sub MyButton1_Click() MyTxtBox1.Text = Now MyTxtBox2.Text = Date MyTxtBox3.Text = Time MyTxtBox4.Text = Format(Now, "Short date") MyTxtBox5.Text = Format(Now, "Long Date") MyTxtBox6.Text = Format(Now, "General date") MyTxtBox7.Text = Format(Now, "Short Time") MyTxtBox8.Text = Format(Now, "Long Time") End SubAfter Executing application, you will find that the following output will be Shown:
VB.Net :
Sub MyDateBtnClick(sender As Object, As EventArgs) MyText1.Text = Now.ToString MyText2.Text = Today.ToString MyText3.Text = TimeOfDay.ToString MyText4.Text = Format(Now, "Short date") MyText5.Text = Format(Now, "Long Date") MyText6.Text = Format(Now, "General date") MyText7.Text = Format(Now, "Short Time") MyText8.Text = Format(Now, "Long Time") End Sub
PreDefined DateTime Format in C#
C# :
void MyDateBtnClick(object sender, EventArgs e) { MyCTxt1.Text = DateTime.Now.ToString(); MyCTxt2.Text = DateTime.Today.ToString(); MyCTxt3.Text = DateTime.Now.TimeOfDay.ToString(); MyCTxt4.Text = DateTime.Now.ToShortDateString(); MyCTxt5.Text = DateTime.Now.ToLongDateString(); MyCTxt6.Text = DateTime.Now.ToLocalTime().ToString(); MyCTxt7.Text = DateTime.Now.ToShortTimeString(); MyCTxt8.Text = DateTime.Now.ToLongTimeString(); }
After compiling this code, you will find the following output, when you click on Button.
So these are the predefined method in VB6, VB.Net and C#. Now Let's Find Custom method or User-Defined Method for Display Date and Time.
How to Create Login Form with Database Connection in Vb6.0?
(2) User-defined Format method :
The following table describe the method of User-defined DateTime Format in VB6.0, VB.Net and C# code.User Defined Format Method | Use |
Format ( now, “Your Formatted String” ) | VB6.0, VB.Net |
Now.Today.ToString ( “Your Formated String” ) | VB.Net |
DateTime.Now.ToString ( “Your Formated String” ) | C#, VB.Net |
DateAndTime.Now.ToString ( “Your Formated String” ) | VB.Net |
Why user defined format method is required? The answer is, in some case or sometime we required specific date time output on their application. So, the user defined format method is used.
SQL Server Connection String with Example and SQL Query Process in VB.Net.
Now, follow the following method for User Defined format process.
VB6.0 :
Private Sub UsrDtBtn_Click() UsrTxtBox1.Text = Format(Now, "dd") UsrTxtBox2.Text = Format(Now, "dddd") UsrTxtBox3.Text = Format(Now, "MM") UsrTxtBox4.Text = Format(Now, "MMMM") UsrTxtBox5.Text = Format(Now, "yyyy") UsrTxtBox6.Text = Format(Now, "dd/MM/yyyy" ) UsrTxtBox7.Text = Format(Now, "dd-MM-yyyy" ) UsrTxtBox8.Text = Format(Now, "MM/dd/yyyy hh:mm:ss AMPM" ) UsrTxtBox9.Text = Format(Now, "hh:mm:ss AMPM" ) UsrTxtBox10.Text = Format(Now, "hh:mm:ss" ) End SubWhen you run VB Form, The following image output will be show.
VB.Net :
Sub UsrDTBtnClick(sender As Object, e As EventArgs) UsrTxt1.Text = Now.ToString("dd/MM/yyyy") UsrTxt2.Text = Now.ToString("MM/dd/yyyy hh:mm:ss tt") UsrTxt3.Text = DateAndTime.Now.ToString("dddd") UsrTxt4.Text = DateAndTime.Now.ToString("MMMM") UsrTxt5.Text = DateTime.Now.ToString("hh:mm:ss tt") UsrTxt6.Text = DateTime.Now.ToString("dddd; dd-MMMM-yyyy") UsrTxt7.Text = Format(Now, "dd-MM-yyyy") UsrTxt8.Text = Format(Now, "MMMM, yyyy") End SubOk, Let's see the output:
C# :
void UserDtBtnClick(object sender, EventArgs e) { DateTime UsrDt; UsrDt = DateTime.Now; MyText1.Text = UsrDt.ToString("dd/MM/yyyy"); MyText2.Text = UsrDt.ToString("MM/dd/yyyy hh:mm:ss tt"); MyText3.Text = UsrDt.ToString("dddd"); MyText4.Text = UsrDt.ToString("MMMM"); MyText5.Text = UsrDt.ToString("hh:mm:ss tt"); MyText6.Text = UsrDt.ToString("dddd; dd-MMMM-yyyy"); MyText7.Text = UsrDt.ToString("MMMM, dd-yyyy"); MyText8.Text = UsrDt.ToString("dd-MMMM-yy"); }After that we get following output:
Now, these are the process to use to Display Date Time in Different DateTime Format in VB6.0 or VB.Net and C# with SKOTechLearn Tips.
Styling ProgressBar with Color Change and Settings in Vb6.0 or VB.Net.
0 comments: