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

Common formats

Output

Formatted result 2024-01-15 13:45:30
Token breakdown
yyyy 2024literal -MM 01literal -dd 15literal HH 13literal :mm 45literal :ss 30
C# code
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 format

Example values are computed from the date currently selected above.

Day
dDay of the month (1–31)15
ddDay of the month, 2 digits (01–31)15
dddAbbreviated day name (Mon)Mon
ddddFull day name (Monday)Monday
Month
MMonth (1–12)1
MMMonth, 2 digits (01–12)01
MMMAbbreviated month name (Jan)Jan
MMMMFull month name (January)January
Year
yyYear, 2 digits (00–99)24
yyyyYear, 4 digits (e.g. 2024)2024
Hour & period
HHour, 24-hour clock (0–23)13
HHHour, 24-hour, 2 digits (00–23)13
hHour, 12-hour clock (1–12)1
hhHour, 12-hour, 2 digits (01–12)01
tFirst char of AM/PM (A or P)P
ttAM/PM designatorPM
Minute, second, fraction
mMinute (0–59)45
mmMinute, 2 digits (00–59)45
sSecond (0–59)30
ssSecond, 2 digits (00–59)30
fffFractional seconds, 3 digits (trailing zeros kept)000
FFFFractional seconds (trailing zeros removed)
Timezone
zUTC offset hours (+0 in this tool)+0
zzUTC offset hours, 2 digits (+00)+00
zzzUTC offset hours:minutes (+00:00)+00:00
KKind/offset — Z for a UTC DateTimeZ

Standard format strings

Single letter — click to use it
dShort date (MM/dd/yyyy)01/15/2024
DLong date (dddd, dd MMMM yyyy)Monday, 15 January 2024
gGeneral short (date + HH:mm)01/15/2024 13:45
GGeneral long (date + HH:mm:ss)01/15/2024 13:45:30
oRound-trip (ISO 8601 with K)2024-01-15T13:45:30.0000000Z
sSortable (yyyy-MM-ddTHH:mm:ss)2024-01-15T13:45:30
RRFC 1123 (… GMT)Mon, 15 Jan 2024 13:45:30 GMT
uUniversal sortable (… Z)2024-01-15 13:45:30Z
tShort time (HH:mm)13:45
TLong time (HH:mm:ss)13:45:30
YYear 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

  1. Pick a date and time, or press Now.
  2. Type a format string or click a common-format chip.
  3. Read the live output and the per-token breakdown.
  4. Copy the ready-to-paste C# snippet.

Detect a format

  1. Switch to Detect format.
  2. Paste an example value such as a date or time.
  3. Review every matching format string.
  4. 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.