Thursday, December 03, 2009

C# DateTime Formats

There are various DateTimeFormats


DateTime.Now; 4/19/2008 7:04:34 AM
DateTime.Now.ToString(); 4/19/2008 7:04:34 AM
DateTime.Now.ToShortTimeString() 7:04 AM
DateTime.Now.ToShortDateString() 4/19/2008
DateTime.Now.ToLongTimeString() 7:04:34 AM
DateTime.Now.ToLongDateString() Saturday, April 19, 2008





DateTime.Now.ToString("d")
4/19/2008
DateTime.Now.ToString("D")
Saturday, April 19, 2008
DateTime.Now.ToString("f")
Saturday, April 19, 2008 7:04 AM
DateTime.Now.ToString("F")
Saturday, April 19, 2008 7:04:34 AM
DateTime.Now.ToString("g")
4/19/2008 7:04 AM
DateTime.Now.ToString("G")
4/19/2008 7:04:34 AM
DateTime.Now.ToString("m")
April 19
DateTime.Now.ToString("r")
Sat, 19 Apr 2008 07:04:34 GMT
DateTime.Now.ToString("s")
2008-04-19T07:04:34
DateTime.Now.ToString("t")
7:04 AM
DateTime.Now.ToString("T")
7:04:34 AM
DateTime.Now.ToString("u")
2008-04-19 07:04:34Z
DateTime.Now.ToString("U")
Saturday, April 19, 2008 12:04:34 PM
DateTime.Now.ToString("y")
April, 2008
DateTime.Now.ToString("dddd, MMMM dd yyyy")
Saturday, April 19 2008
DateTime.Now.ToString("ddd, MMM d "'"yy")
Sat, Apr 19 '08
DateTime.Now.ToString("dddd, MMMM dd")
Saturday, April 19
DateTime.Now.ToString("M/yy")
4/08
DateTime.Now.ToString("dd-MM-yy")
19-04-08


Parsing Date At ASPX page

<#DateTime.Parse(Eval("DateColumnName").ToString()).ToString("MMM dd, yyyy")%>

Parsing Date At .CS page

string dt=DateTime.Parse(appdate).ToString("MM/dd/yyyy");

Some DateTime Conversion in SP

Style ID

Style Type

0 or 100 mon dd yyyy hh:miAM (or PM)
101 mm/dd/yy
102 yy.mm.dd
103 dd/mm/yy
104 dd.mm.yy
105 dd-mm-yy
106 dd mon yy
107 Mon dd, yy
108 hh:mm:ss
9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM)
110 mm-dd-yy
111 yy/mm/dd
112 yymmdd
13 or 113 dd mon yyyy hh:mm:ss:mmm(24h)
114 hh:mi:ss:mmm(24h)
20 or 120 yyyy-mm-dd hh:mi:ss(24h)
21 or 121 yyyy-mm-dd hh:mi:ss.mmm(24h)
126 yyyy-mm-dd Thh:mm:ss.mmm(no spaces)
130 dd mon yyyy hh:mi:ss:mmmAM
131 dd/mm/yy hh:mi:ss:mmmAM