Format the current date in various ways : Date Format « Date Time « VB.Net Tutorial






Imports System
Imports Microsoft.VisualBasic

Class Sample
   Public Shared Sub Main()
      Dim thisDate As DateTime = DateTime.Now


      Console.WriteLine("Standard DateTime Format Specifiers")
      Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
                        "(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
                        "(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
                        "(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
                        "(f) Full date/short time: . . {0:f}" & vbCrLf & _
                        "(F) Full date/long time:. . . {0:F}" & vbCrLf & _
                        "(g) General date/short time:. {0:g}" & vbCrLf & _
                        "(G) General date/long time: . {0:G}" & vbCrLf & _
                        "    (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
                        "(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
                        "(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
                        "(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
                        "(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
                        "(U) Universal full date/time: {0:U}" & vbCrLf & _
                        "(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
                        thisDate)

   End Sub
End Class








5.2.Date Format
5.2.1.Use format specifiers to control the date display
5.2.2.Date format: dd
5.2.3.Date format: ddd
5.2.4.Date format: dddd
5.2.5.Date format: HH:mm:ss.fff z
5.2.6.Date format: yy/MM/dd g
5.2.7.Date format: s, u, Z
5.2.8.Date format: {0:dddd},
5.2.9.Date format: {0:d} ;{1:D}
5.2.10.Date format: {0:t} ;{1:T}
5.2.11.Date format: {0:f} ;{1:F}
5.2.12.Date format: {0:g} ;{1:G}
5.2.13.Date format: {0:m} ;{1:M}
5.2.14.Date format: {0:yyyy/MM/dd HH:mm:ss}
5.2.15.Date format: {0:MMMM-dd-yy HH:mm:ss}
5.2.16.Format the current date in various ways
5.2.17.Date and time and numeric values using several different cultures.
5.2.18.Custom Format Strings
5.2.19.Defines a custom format string that displays the day of the week in parentheses after the month name, day, and year.