C# DateTime Formatter
Format a date with any .NET DateTime.ToString() pattern — or paste an example and detect the format string. Works for full dates and time-only values.
Input
Output
var dt = new DateTime(2024, 1, 15, 13, 45, 30, DateTimeKind.Utc);
string result = dt.ToString(@"yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
// result = "2024-01-15 13:45:30" Custom format specifiers
Click a row to add it to your formatExample values are computed from the date currently selected above.
| d | Day of the month (1–31) | 15 |
| dd | Day of the month, 2 digits (01–31) | 15 |
| ddd | Abbreviated day name (Mon) | Mon |
| dddd | Full day name (Monday) | Monday |
| M | Month (1–12) | 1 |
| MM | Month, 2 digits (01–12) | 01 |
| MMM | Abbreviated month name (Jan) | Jan |
| MMMM | Full month name (January) | January |
| yy | Year, 2 digits (00–99) | 24 |
| yyyy | Year, 4 digits (e.g. 2024) | 2024 |
| H | Hour, 24-hour clock (0–23) | 13 |
| HH | Hour, 24-hour, 2 digits (00–23) | 13 |
| h | Hour, 12-hour clock (1–12) | 1 |
| hh | Hour, 12-hour, 2 digits (01–12) | 01 |
| t | First char of AM/PM (A or P) | P |
| tt | AM/PM designator | PM |
| m | Minute (0–59) | 45 |
| mm | Minute, 2 digits (00–59) | 45 |
| s | Second (0–59) | 30 |
| ss | Second, 2 digits (00–59) | 30 |
| fff | Fractional seconds, 3 digits (trailing zeros kept) | 000 |
| FFF | Fractional seconds (trailing zeros removed) |
| z | UTC offset hours (+0 in this tool) | +0 |
| zz | UTC offset hours, 2 digits (+00) | +00 |
| zzz | UTC offset hours:minutes (+00:00) | +00:00 |
| K | Kind/offset — Z for a UTC DateTime | Z |
Standard format strings
Single letter — click to use it| d | Short date (MM/dd/yyyy) | 01/15/2024 |
| D | Long date (dddd, dd MMMM yyyy) | Monday, 15 January 2024 |
| g | General short (date + HH:mm) | 01/15/2024 13:45 |
| G | General long (date + HH:mm:ss) | 01/15/2024 13:45:30 |
| o | Round-trip (ISO 8601 with K) | 2024-01-15T13:45:30.0000000Z |
| s | Sortable (yyyy-MM-ddTHH:mm:ss) | 2024-01-15T13:45:30 |
| R | RFC 1123 (… GMT) | Mon, 15 Jan 2024 13:45:30 GMT |
| u | Universal sortable (… Z) | 2024-01-15 13:45:30Z |
| t | Short time (HH:mm) | 13:45 |
| T | Long time (HH:mm:ss) | 13:45:30 |
| Y | Year month (yyyy MMMM) | 2024 January |
About C# DateTime Formatter
C# DateTime Formatter is a free, two-way playground for .NET date formatting. In C# you turn a date into a string with DateTime.ToString(), using pattern letters such as yyyy for the four-digit year, MM for the month, and HH:mm:ss for the time. Case and the number of letters matter — MM is the month while mm is the minute. This tool lets you experiment and see the exact output instantly.
It also works in reverse. Paste an example like 00:00:00 and the detector reports the matching format string HH:mm:ss, ready to drop into DateTime.ParseExact(). Output uses the invariant culture and runs entirely in your browser — nothing is sent to a server.
How to Use C# DateTime Formatter
Format a date
- Pick a date and time, or press Now.
- Type a format string or click a common-format chip.
- Read the live output and the per-token breakdown.
- Copy the ready-to-paste C# snippet.
Detect a format
- Switch to Detect format.
- Paste an example value such as a date or time.
- Review every matching format string.
- Press Use to load it into format mode, or copy it.
Tip: a single character is read as a standard specifier, so use %d for a one-character custom day, quote literals like 'GMT', and remember MM is month while mm is minute.
FAQ
What is the difference between format and detect mode?
Format mode is the classic direction: you pick a date and a format string (like yyyy-MM-dd HH:mm:ss) and instantly see the output, the same result .NET returns from DateTime.ToString(). Detect mode is the reverse: you paste an example such as 00:00:00 and the tool tells you the matching format string is HH:mm:ss, ready to use with DateTime.ParseExact().
Why does a single letter like "d" give a full date instead of the day?
In .NET a one-character format string is treated as a standard format specifier, not a custom one. So "d" means the short-date pattern (01/15/2024), not day-of-month. To get a single custom specifier, prefix it with a percent sign — "%d" gives just the day. Two or more characters are always parsed as a custom pattern.
Does this match .NET exactly?
The custom specifiers and standard format strings follow the official Microsoft documentation, using the invariant culture (English). All date and time parts are computed in UTC so the output is deterministic. The K specifier outputs Z (a UTC DateTime) and the z specifiers report a +00:00 offset.
Why does an example return more than one format?
Some inputs are genuinely ambiguous. 01/02/2024 could be dd/MM/yyyy (2 January) or MM/dd/yyyy (1 February). The detector shows every pattern that reproduces your example exactly so you can choose the right one.
How do I include literal text or escape a letter?
Wrap literal text in single or double quotes — "yyyy 'year'" prints 2024 year — or escape a single character with a backslash, like yyyy\MMM. Letters that are format specifiers (d, M, y, H, h, m, s, f, t, z, K) must be quoted or escaped to appear literally.