skip to main content

Date formatting

15 November, 2020

Posted in code
Tagged misc

The table below shows all the available date formatting options in most programming languages.

Example’s of how to use these formats include:

@DateTime.Now.ToString("F")

@DateTime.Now.ToString("hh:mm:ss.fff")
SpecifierDescriptionOutput
dShort Date08/04/2007
DLong Date08 April 2007
tShort Time21:08
TLong Time21:08:59
fFull date and time08 April 2007 21:08
FFull date and time (long)08 April 2007 21:08:59
gDefault date and time08/04/2007 21:08
GDefault date and time (long)08/04/2007 21:08:59
MDay / Month08 April
rRFC1123 dateSun, 08 Apr 2007 21:08:59 GMT
sSortable date/time2007-04-08T21:08:59
uUniversal time, local timezone2007-04-08 21:08:59Z
YMonth / YearApril 2007
ddDay08
dddShort Day NameSun
ddddFull Day NameSunday
hh2 digit hour09
HH2 digit hour (24 hour)21
mm2 digit minute08
MMMonth04
MMMShort Month nameApr
MMMMMonth nameApril
ssseconds59
fffmilliseconds120
FFFmilliseconds without trailing zero12
ttAM/PMPM
yy2 digit year07
yyyy4 digit year2007
:Hours, minutes, seconds separator, e.g. {0:hh:mm:ss}09:08:59
/Year, month , day separator, e.g. {0:dd/MM/yyyy}08/04/2007
.milliseconds separator

These specifiers are the same for most programming languages, making this a valuable resource for everyone.