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.
| Specifier | Meaning | Example |
d | Short date. | 8/20/2015 |
D | Long date. | Thursday, August 20, 2015 |
t | Short time. | 2:37 PM |
T | Long time. | 2:37:18 PM |
f | Full date/time with short time. | Thursday, August 20, 2015 2:37 PM |
F | Full date/time with long time. | Thursday, August 20, 2015 2:37:18 PM |
g | General date/time with short time. | 8/20/2015 2:37 PM |
G | General date/time with long time. | 8/20/2015 2:37:18 PM |
m or M | Month and date. | August 20 |
r or R | RFC1123 pattern. Formatting does not convert the time to Greenwich Mean Time (GMT), so you should ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access