Sunday, November 21, 2010

Formatting Dates, Times in ASP.NET 4.0


Format DescriptionCode SnippetOutput
Short date pattern (d) DateTime.Now.ToString("d")11/8/2010
Long date pattern (D) DateTime.Now.ToString("D")Monday, November 08, 2010
Full date/time pattern - short time (f)DateTime.Now.ToString("f") Monday, November 08, 2010 3:39 PM
Full date/time pattern - long time (F) DateTime.Now.ToString("F") Monday, November 08, 2010 3:39:46 PM
General date/time pattern - short time (g) DateTime.Now.ToString("g")11/8/2010 3:39 PM
General date/time pattern - long time (G) DateTime.Now.ToString("G")11/8/2010 3:39:46 PM
Month/day pattern (M)DateTime.Now.ToString("M") November 08
Round-trip date/time pattern (O) DateTime.Now.ToString("O") 2010-11-08T15:39:46.4804000-08:00
RFC 1123 pattern (R) DateTime.Now.ToString("R")Mon, 08 Nov 2010 15:39:46 GMT
Sortable date/time pattern (s) DateTime.Now.ToString("s")2010-11-08T15:39:46
Short time pattern (t)DateTime.Now.ToString("t") 3:39 PM
Long time pattern (T) DateTime.Now.ToString("T")3:39:46 PM
Universal sortable date/time pattern (u)DateTime.Now.ToString("u") 2010-11-08 15:39:46Z
Universal full date/time pattern (U) DateTime.Now.ToString("U") Monday, November 08, 2010 11:39:46 PM
Year/month pattern (Y) DateTime.Now.ToString("Y")November, 2010


No comments: