Appendix P Date and Time Format Specifiers

A program uses date and time format specifiers to determine how dates and times are represented as strings. C# provides two kinds of specifiers that you can use to determine a date and time value’s format: standard format specifiers and custom format specifiers.

Standard format specifiers are locale-aware, so the result depends on the computer’s regional settings. For that reason, you should always use the standard specifiers whenever possible.

The following sections describe the available standard and custom date and time format specifiers.

Standard Format Specifiers

A standard format specifier is a single character that you use alone to indicate a standardized format. For example, the format string d indicates a short date format (as in 8/20/2012).

The following table lists standard format specifiers that you can use to format date and time strings. The examples shown in this table are for a typical computer in the United States.

SpecifierMeaningExample
dShort date.8/20/2015
DLong date.Thursday, August 20, 2015
tShort time.2:37 PM
TLong time.2:37:18 PM
fFull date/time with short time.Thursday, August 20, 2015 2:37 PM
FFull date/time with long time.Thursday, August 20, 2015 2:37:18 PM
gGeneral date/time with short time.8/20/2015 2:37 PM
GGeneral date/time with long time.8/20/2015 2:37:18 PM
m or MMonth and date.August 20
r or RRFC1123 pattern. Formatting does not convert the time to Greenwich Mean Time (GMT), so you should ...

Get C# 5.0 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.