June 20, 2013

C# Date Format Cheat Sheet

The date format is use to format custom date according to user need. Simply pass the specifier of your choice from below table.
<%= String.Format("{specifier}", DateTime.Now) %>

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
ttAM/PMPM
yy2 digit year07
yyyy4 digit year2007
:seperator, e.g. {0:hh:mm:ss}09:08:59
/seperator, e.g. {0:dd/MM/yyyy}08/04/2007