|
|
Title | Use the FormatDateTime function in Visual Basic .NET |
Description | This example shows how to use the FormatDateTime function in Visual Basic .NET. |
Keywords | FormatDateTime, format date, format time, format datetime, VB.NET |
Categories | Strings, VB.NET |
|
|
The FormatDateTime function returns a formatted string representation for a date and/or time. The syntax is:
FormatPercent(expression [, format] )
Where:
- expression
- The numeric expression to format
- format
- A date/time formatting value
The result depends on your system's locale. Examples (in the United States):
Expression | Result |
FormatDateTime(Now, DateFormat.GeneralDate) | 6/27/2006 10:55:06 AM |
FormatDateTime(Now, DateFormat.LongDate) | Thursday, June 27, 2006 |
FormatDateTime(Now, DateFormat.ShortDate) | 6/27/2006 |
FormatDateTime(Now, DateFormat.LongTime) | 10:55:06 AM |
FormatDateTime(Now, DateFormat.ShortTime) | 10:55 |
This example uses the following code to display these examples in a TextBox.
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim txt As String
txt &= "FormatDateTime(Now, DateFormat.GeneralDate) = " _
& FormatDateTime(Now, DateFormat.GeneralDate) & _
vbCrLf
txt &= "FormatDateTime(Now, DateFormat.LongDate) = " & _
FormatDateTime(Now, DateFormat.LongDate) & vbCrLf
txt &= "FormatDateTime(Now, DateFormat.ShortDate) = " & _
FormatDateTime(Now, DateFormat.ShortDate) & vbCrLf
txt &= "FormatDateTime(Now, DateFormat.LongTime) = " & _
FormatDateTime(Now, DateFormat.LongTime) & vbCrLf
txt &= "FormatDateTime(Now, DateFormat.ShortTime) = " & _
FormatDateTime(Now, DateFormat.ShortTime) & vbCrLf
txtResult.Text = txt
txtResult.Select(0, 0)
End Sub
|
|
|
|
|
|