NumberFormatInfo
Again, both standard format Strings and custom format Strings and the output are influenced by the culture
context associated with the current thread or a CultureInfo object passed to the ToString method (see also
Chapter 4). Custom format Strings allow you to be more flexible and are useful in the rare occasions that the
standard formatters are insufficient.
Table 15−5 provides the list of standard DateTime format Strings. These Strings are interpreted as standard
format specifiers if they contain only one of the single format specifiers listed here. Some of the formatters
have specific nuances that may require escape characters and certain treatment to obtain the desired result. Be
sure to consult the .NET Framework SDK for specifics.
The formatters will throw ArgumentException if the specified format characters are not expected by the
receiving method. As long as you stick to the characters in the table, you will not have a problem.
Table 15−5: The Standard DateTime Formatters and property/patterns associated with the current thread or by
a specified format provider
Format Specifier Output
d Short date pattern displays a pattern defined by
DateTimeFormatInfo.ShortDatePattern property
D Long date pattern displays a pattern defined by the
DateTimeFormatInfo.LongDatePattern property
t Short time pattern displays a pattern defined by the
DateTimeFormatInfo.ShortTimePattern property
T Long time pattern displays a pattern defined by the
DateTimeFormatInfo.LongTimePattern property
f Full date/time pattern (short time) displays a combination of the long date and
short time patterns, separated by a space
F Full date/time pattern (long time) displays a pattern defined by the
DateTimeFormatInfo.FullDateTimePattern property
g General date/time pattern (short time) displays a combination of the short date
and short time patterns, separated by a space
G General date/time pattern (long time) displays a combination of the short date
and long time patterns, separated by a space
M or m Month day pattern displays a pattern defined by
DateTimeFormatInfo.MonthDayPattern property
R or r RFC1123 pattern displays a pattern defined by the
DateTimeFormatInfo.RFC1123Pattern property
s Sortable date/time pattern that conforms to ISO 8601. It displays a pattern
defined by the DateTimeFormatInfo.SortableDateTimePattern property.
The property references the CultureInfo.InvariantCulture property, and the
format follows the custom pattern "yyyy−MM−ddTHH:mm:ss."
u Universal sortable date/time pattern displays a pattern defined by the
DateTimeFormatInfo.UniversalSortableDateTime Pattern property.
Because it is a defined standard and the property is read−only, the pattern is
always the same regardless of culture or format provider. The format follows
the custom pattern "yyyy−MM−dd HH:mm:ssZ."
U
509