Chitika

Monday, October 8, 2012

Date Formats in C#

In c# we can format date in different ways , there are some predefined date formats in c# . 
We can do customization based on the location and other parameters.
If you want to give specific format then specify the specifier in the below statement.


<%= String.Format("{specifier}", DateTime.Now) %>
This you need to mention in your source page.

The predefined format are 
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

No comments:

Post a Comment