Wednesday, March 14, 2007

Date formatting

Some of the formats for date formatting.
specifier type output
dd Day 08
ddd Short Day Name Mon
dddd Full Day Name Monday
hh 2 digit hour 12
HH 2 digit hour (24 hour) 12
mm 2 digit minute 30
MM Month 06
MMM Short Month name Jun
MMMM Month name June
ss seconds 59
tt AM/PM PM
yy 2 digit year 70
yyyy 4 digit year 1970
: seperator, e.g. {0:hh:mm:ss} 12:30:59
/ seperator, e.g. {0:dd/MM/yyyy} 08/06/1970

Can simply be used with string as well.
for example,
string date=DateTime.Now.ToString("yyyy");

In some controls there is a DataFormatString property as well:
DataFormatString="{0:g}"

No comments: