Tuesday, December 2, 2008

C#: DateTime.ToString()

Looking for simple, direct examples of what the various DateTime conversion functions do which MSDN was completely incapable of providing. Found a great tutorial article that summarized them nicely:
result = theDate.ToString("y");       // result = "January 2007"
SpecifierDescriptionExample
dShort date format. This is equivalent to using ToShortDateString."03/01/2007"
DLong date format. This is equivalent to using ToLongDateString."03 January 2007"
fDate and time using long date and short time format."03 January 2007 21:25"
FDate and time using long date and time format."03 January 2007 21:25:30"
gDate and time using short date and time format."03/01/2007 21:25"
GDate and time using short date and long time format."03/01/2007 21:25:30"
mDay and month only."03 January"
rDate and time in standard Greenwich Mean Time (GMT) format."Wed, 03 Jan 2007 21:25:30 GMT"
sSortable date and time format. The date elements start at the highest magnitude (year) and reduce along the string to the smallest magnitude (seconds)."2007-01-03T21:25:30"
tShort time format. This is equivalent to using ToShortTimeString."21:25"
TLong time format. This is equivalent to using ToLongTimeString."21:25:30"
uShort format, sortable co-ordinated universal time."2007-01-03 21:25:30Z"
ULong format date and time."03 January 2007 17:25:30"
yMonth and year only."January 2007"