Date Format Masks


.NET Date and Time Format Masks

Standard Format Masks

Standard format masks are single-character specifiers that represent common date and time formats. The output varies based on the system's culture settings.

Character Description Example (en-US)
d Short date 1/1/2001
D Long date Monday, January 1, 2001
f Full date/time (long date + short time) Monday, January 1, 2001 10:30 AM
F Full date/time (long date + long time) Monday, January 1, 2001 10:30:22 AM
g General date/time (short date + short time) 1/1/2001 10:30 AM
G General date/time (short date + long time) 1/1/2001 10:30:22 AM
m / M Month and day January 1
r / R RFC 1123 format Mon, 1 Jan 2001 10:30:22 GMT
t Short time 10:30 AM
T Long time 10:30:22 AM
y / Y Year and month January 2001

Custom Format Masks

Custom format masks allow you to build precise, culture-independent date and time formats using specific patterns.

Pattern Description Example
d Day of month (no leading zero) 1
dd Day of month (with leading zero) 01
ddd Abbreviated day of week Mon
dddd Full day of week Monday
M Month (no leading zero) 1
MM Month (with leading zero) 01
MMM Abbreviated month name Jan
MMMM Full month name January
y Year (last two digits, no leading zero) 1
yy Year (last two digits, with leading zero) 01
yyyy Full year (four digits) 2001
h Hour (12-hour, no leading zero) 1
hh Hour (12-hour, with leading zero) 01
H Hour (24-hour, no leading zero) 1
HH Hour (24-hour, with leading zero) 01
m Minute (no leading zero) 1
mm Minute (with leading zero) 01
s Second (no leading zero) 1
ss Second (with leading zero) 01
ffffffff Fractions of a second (1–7 digits) 1 to 1111111
t First character of AM/PM A or P
tt AM/PM designator AM or PM
z Time zone offset (e.g., -8) -8
zz Time zone offset with leading zero -08
zzz Full time zone offset -08:00
: Time separator (culture-specific) :
/ Date separator (culture-specific) /
\c Escape character (e.g., \\ for backslash) \ or \\