Header Ads

Date Time Format in C#

C#
FormatDescriptionOutput
dShort Date06/04/2016
DLong Date06 April 2016
tShort Time10:48
TLong Time10:48:59
fFull date and time06 April 2016 10:08
FFull date and time (long)06 April 2016 10:48:59
gDefault date and time06/04/2007 11:08
GDefault date and time (long)06/04/2016 11:08:59
MDay / Month06 April
rRFC1123 dateWed, 06 Apr 2016 11:08:59 GMT
sSortable date/time2016-04-06T11:08:59
uUniversal time, local timezone2016-04-06 11:08:59Z
YMonth / YearApril 2016
ddDay06
dddShort Day NameWed
ddddFull Day NameWednesday
hh2 digit hour06
HH2 digit hour (24 hour)21
mm2 digit minute06
MMMonth04
MMMShort Month nameApr
MMMMMonth nameApril
ssseconds59
fffmilliseconds120
FFFmilliseconds without trailing zero12
ttAM/PMAM
yy2 digit year16
yyyy4 digit year2016
:Hours, minutes, seconds separator, e.g. {0:hh:mm:ss}11:08:59
/Year, month , day separator, e.g. {0:dd/MM/yyyy}06/04/2016
Example:
<%= String.Format("{Format}", DateTime.Now) %>
@DateTime.Now.ToString("F")
@DateTime.Now.ToString("hh:mm:ss.fff")

No comments:



Powered by Blogger.