.NET Code Tips

Free .NET developer tool

.NET Format String Tester

Type a format like yyyy-MM-dd, o, N2 or #,##0.00, pick a culture, and see exactly what ToString prints — checked against real .NET output.

Runs entirely in your browser — nothing you paste is uploaded.

Try:
Result
Monday, March 9, 2026 2:05 PM
SpecifierMeaningOutput
ddddFull day nameMonday
", "Copied as is: comma, space", "
MMMMFull month nameMarch
" "Copied as is: space" "
dDay of the month, 1–319
", "Copied as is: comma, space", "
yyyyYear, at least 4 digits2026
" "Copied as is: space" "
hHour, 12-hour clock, 1–122
:Time separator of the culture:
mmMinute, 00–5905
" "Copied as is: space" "
ttAM/PM designatorPM

Standard date and time formats

Every standard format applied to your value in English (United States). Click a row to use it.

FormatNameResult
Short date
M/d/yyyy
3/9/2026
Long date
dddd, MMMM d, yyyy
Monday, March 9, 2026
Full date, short time
dddd, MMMM d, yyyy h:mm tt
Monday, March 9, 2026 2:05 PM
Full date, long time
dddd, MMMM d, yyyy h:mm:ss tt
Monday, March 9, 2026 2:05:07 PM
General: short date, short time
M/d/yyyy h:mm tt
3/9/2026 2:05 PM
General: short date, long time (the default)
M/d/yyyy h:mm:ss tt
3/9/2026 2:05:07 PM
Month and day
MMMM d
March 9
Round-trip ISO 8601
yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK
2026-03-09T14:05:07.1234560Z
RFC 1123
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Mon, 09 Mar 2026 14:05:07 GMT
Sortable ISO 8601
yyyy'-'MM'-'dd'T'HH':'mm':'ss
2026-03-09T14:05:07
Short time
h:mm tt
2:05 PM
Long time
h:mm:ss tt
2:05:07 PM
Universal sortable
yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2026-03-09 14:05:07Z
Universal full date and time (DateTime only)
dddd, MMMM d, yyyy h:mm:ss tt
Monday, March 9, 2026 2:05:07 PM
Year and month
MMMM yyyy
March 2026

Culture data from .NET 10.0.12 on macOS (ICU). Windows has used ICU too since .NET 5, so results match there, except where Windows' own NLS data is turned back on.

The code

Program.cs
using System.Globalization;

var value = new DateTime(2026, 3, 9, 14, 5, 7, DateTimeKind.Utc).AddTicks(1234560);
string s = value.ToString("dddd, MMMM d, yyyy h:mm tt", CultureInfo.GetCultureInfo("en-US"));
// "Monday, March 9, 2026 2:05 PM"

// In an interpolated string (uses CultureInfo.CurrentCulture):
string t = $"{value:dddd, MMMM d, yyyy h:mm tt}";

Standard or custom?

A format string of a single letter, or a letter followed by digits such as N2 or X8, is a standard format: a shortcut whose output depends on the culture. Anything else is a custom format built from specifiers such as yyyy, MM or #,##0.00. That's why ToString("d") prints a whole short date: to get just the day of the month, write "%d".

Culture matters more than you'd think

ToString() without a provider uses CultureInfo.CurrentCulture, which on a server is whatever the OS or container is set to. In custom date formats the / and : characters are replaced by the culture's separators, month and day names are translated, and in Russian or Polish a month name next to a day number takes its genitive form ("9 марта", not "9 март"). For logs, file names, JSON and anything read back by code, pass CultureInfo.InvariantCulture or use "o".

Rounding

double standard formats round the exact binary value, with ties going to the even digit, so 2.5.ToString("F0") is "2". decimal rounds half away from zero, so 2.5m.ToString("F0") is "3". Custom numeric formats on a double round to 15 significant digits first, then half up. If the rule matters, call Math.Round(value, digits, MidpointRounding.AwayFromZero) before formatting.

Frequently asked questions

Why does ToString("MM/dd/yyyy") print dots instead of slashes on some servers?

In a custom date format "/" isn’t a literal slash: it means the culture’s DateSeparator, and ":" means its TimeSeparator, so "MM/dd/yyyy" prints "03.09.2026" when the current culture is de-DE. Other characters, such as hyphens, are always literal. For machine-readable output use the round-trip "o" format or pass CultureInfo.InvariantCulture, and escape a separator you always want, as in "yyyy'/'MM'/'dd".

What is the difference between "o", "s" and "u" for dates?

"o" is the ISO 8601 round-trip format with seven fractional digits and the offset or Z ("2026-03-09T14:05:07.1234560Z"), so DateTime.Parse can restore the exact value and Kind. "s" is ISO 8601 without fraction or offset. "u" is like "s" with a space instead of the T and a trailing Z, but on a DateTime it doesn’t convert to UTC — it just appends Z — while DateTimeOffset converts first. All three always use the invariant culture.

Why does 2.5.ToString("F0") return 2 but 2.5m.ToString("F0") return 3?

Since .NET Core 3.0, double and float formatting is IEEE-correct: standard formats round the exact binary value, and an exact tie such as 2.5 rounds to the even digit. decimal and the integer types round half away from zero. Custom formats such as "0" or "#,##0.00" on a double first take 15 significant digits and then round half up. When you need a particular rounding rule, call Math.Round with a MidpointRounding mode before formatting.

How do I format a number with thousands separators and two decimals in C#?

Use the "N2" standard format — 1234567.891.ToString("N2") gives "1,234,567.89" in en-US and "1.234.567,89" in de-DE — or the custom format "#,##0.00", which behaves the same but lets you add sections for negative numbers and zero, such as "#,##0.00;(#,##0.00);-". Pass CultureInfo.InvariantCulture if the output must not change with the server’s regional settings.