Wednesday, April 2, 2014

Date Formatting in C#

Example Usage

<%= String.Format("{specifier}", DateTime.Now) %>
@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
.
Reference: http://www.mikesdotnetting.com/Article/23/Date-Formatting-in-CSharp
milliseconds separator

No comments:

Post a Comment