C# custom format tokens.
Letter-repetition tokens in the CLDR style, with one trap all of its own: a single-character format string is a STANDARD format, not a custom token — "d" alone means the short-date pattern and "%d" (or any second character) is needed to get the day number. Month and weekday names follow the culture passed to ToString. For serialization, prefer the K specifier: it renders Z for UTC, the offset for local times, and nothing for unspecified kinds, which is what round-tripping needs. There are no tokens for day of year, week numbers (use the ISOWeek class), quarters, unix timestamps, or time-zone names — only offsets.
| Token | Means | Example |
|---|---|---|
| yyyy | Four-digit year | 2006 |
| yy | Two-digit year A single y gives the unpadded 0–99 year; yyy and up pad to that many digits. | 06 |
| M | Month number As a complete format string, "M" is the standard month/day pattern — write "%M". | 1 |
| MM | Month number, padded | 01 |
| MMM | Month name, abbreviated Culture-sensitive: Jun in en-US, juin in fr-FR. | Jan |
| MMMM | Month name, full | January |
| d | Day of month As a complete format string, "d" is the standard short-date pattern — write "%d". | 2 |
| dd | Day of month, padded | 02 |
| ddd | Weekday, abbreviated | Mon |
| dddd | Weekday, full | Monday |
| H | Hour, 24-hour clock Alone it must be written "%H" to avoid the standard-format lookup. | 15 |
| HH | Hour, 24-hour clock, padded | 15 |
| h | Hour, 12-hour clock Alone it must be written "%h". | 3 |
| hh | Hour, 12-hour clock, padded | 03 |
| tt | AM/PM marker A single t prints only the first character (P) of the designator. | PM |
| mm | Minute, padded A bare m (as "%m") gives the unpadded minute. | 04 |
| ss | Second, padded A bare s (as "%s") gives the unpadded second. | 05 |
| fff | Fractional seconds Each f is one digit, up to fffffff (100 ns); uppercase F trims trailing zeros instead of printing them. | 000 |
| zzz | UTC offset, extended zz gives hours only (-07), z unpadded (-7). Prefer K when round-tripping: Z for UTC, empty for unspecified. | -07:00 |
| g | Era Renders A.D.; gg is identical. | AD |
Examples render the reference instant, Mon, Jan 2 2006, 3:04:05 PM MST.
Literal text
Backslash escapes one character (\h); longer runs go in 'single' or "double" quotes. Beware that : and / are culture-dependent separator specifiers, not literals — escape them for a fixed output.
Verified against .NET docs — custom date and time format strings.