Monday, July 23, 2007

I've included a quick "DateTime.ToString Format" lookup. Very useful if you're having trouble remembering 40+ DateTime format specifiers.

The following specifiers and their results are based on the following date:
January 3, 0001 A.D., 02:09:20.444 P.M. - thank you MSDN :)

Custom format string Yields
-------------------- ------
"%y" "1"
"yy" "01"
"yyy" "001"
"yyyy" "0001"
"yyyyy" "00001"
"%M" "1"
"MM" "01"
"MMM" "Jan"
"MMMM" "January"
"%d" "3"
"dd" "03"
"ddd" "Wed"
"dddd" "Wednesday"
"%g" "A.D."
"gg" "A.D."
"%h" "2"
"hh" "02"
"%H" "14"
"HH" "14"
"%m" "9"
"mm" "09"
"%s" "20"
"ss" "20"
"%f" "4"
"ff" "44"
"fff" "444"
"ffff" "4440"
"fffff" "44400"
"ffffff" "444000"
"fffffff" "4440000"
"%F" "4"
"FF" "44"
"FFF" "444"
"FFFF" "444"
"FFFFF" "444"
"FFFFFF" "444"
"FFFFFFF" "444"
"%t" "P"
"tt" "PM"
"%z" "-8"
"zz" "-08"
"zzz" "-08:00"
"'The year is' yyyy" "The year is 0001"
""The year is" yyyy" "The year is 0001"
"\\" "\"

If we format different kinds of DateTime's using "K"
DateTimeKind Yields
------------ ------
Unspecified ""
Utc "Z"
Local "-08:00"

posted on Monday, July 23, 2007 6:10:33 PM (South Africa Standard Time, UTC+02:00)  #    Trackback
Related posts: