A standard date and time format string uses a single format specifier to define the text representation of a date and time value that is produced by a formatting operation. Any date and time format string that contains more than one character, including white space, is interpreted as a custom date and time format string. For more information, see Custom DateTime Format Strings.
The following table describes the standard date and time format specifiers.
Format specifier |
Description |
Examples |
---|---|---|
"d" |
Short date pattern. |
6/15/2009 1:45:30 PM -> 6/15/2009 (en-US) |
"D" |
Long date pattern. |
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 (en-US) |
"f" |
Full date/time pattern (short time). |
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45 PM (en-US) |
"F" |
Full date/time pattern (long time). |
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45:30 PM (en-US) |
"g" |
General date/time pattern (short time). |
6/15/2009 1:45:30 PM -> 6/15/2009 1:45 PM (en-US) |
"G" |
General date/time pattern (long time). |
6/15/2009 1:45:30 PM -> 6/15/2009 1:45:30 PM (en-US) |
"M", "m" |
Month/day pattern. |
6/15/2009 1:45:30 PM -> June 15 (en-US) |
"O", "o" |
Round-trip date/time pattern. |
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000 |
"R", "r" |
RFC1123 pattern. |
6/15/2009 1:45:30 PM -> Mon, 15 Jun 2009 20:45:30 GMT |
"s" |
Sortable date/time pattern. |
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30 |
"t" |
Short time pattern. |
6/15/2009 1:45:30 PM -> 1:45 PM (en-US) |
"T" |
Long time pattern. |
6/15/2009 1:45:30 PM -> 1:45:30 PM (en-US) |
"u" |
Universal sortable date/time pattern. |
6/15/2009 1:45:30 PM -> 2009-06-15 20:45:30Z |
"U" |
Universal full date/time pattern. |
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 8:45:30 PM (en-US) |
"Y", "y" |
Year month pattern. |
6/15/2009 1:45:30 PM -> June, 2009 (en-US) |
Any other single character |
Unknown specifier. |
error |
See Standard Date and Time Format Strings on MSDN for more information.