Custom DateTime Format Strings Output Examples

The following table illustrates the output created by applying some custom DateTime format strings to a particular date and time. Output was produced using the ToString method.

The Format specifiers column indicates the format string, the Current culture column indicates the culture associated with the current thread, the Time zone column indicates the time zone in effect when formatting, and the Output column indicates the result of formatting.

The different culture and time zone values demonstrate the impact of changing the current culture. The culture can be changed by using the Date/Time control panel in Microsoft Windows, by passing your own DateTimeFormatInfo as the format provider, or by passing a CultureInfo set to a different culture.

Format specifiers Current culture Time zone Output
d, M en-US GMT 12, 4
d, M es-MX GMT 12, 4
d MMMM en-US GMT 12 April
d MMMM es-MX GMT 12 Abril
dddd MMMM yy gg en-US GMT Thursday April 01 A.D.
dddd MMMM yy gg es-MX GMT Jueves Abril 01 DC
h , m: s en-US GMT 6 , 13: 12
hh,mm:ss en-US GMT 06,13:12
HH-mm-ss-tt en-US GMT 06-13-12-AM
hh:mm, G\MT z en-US GMT 05:13 GMT +0
hh:mm, G\MT z en-US GMT +10:00 05:13 GMT +10
hh:mm, G\MT zzz en-US GMT 05:13 GMT +00:00
hh:mm, G\MT zzz en-US GMT –9:00 05:13 GMT -09:00

Note that in some languages such as C#, the '\' character must be preceded by an escape character when used with the ToString method.

See Also

Formatting Overview | Formatting Types | Custom DateTime Format Strings | Standard DateTime Format Strings