Monday, 22 September 2008

How to convert DateTime

Here is a list of ways to convert DateTime.

DateTime.Now; - 9/17/2007 8:29:25 AM
DateTime.Now.ToString(); - 9/17/2007 8:29:25 AM
DateTime.Now.ToShortTimeString(); - 8:29 AM
DateTime.Now.ToShortDateString(); - 9/17/2007
DateTime.Now.ToLongTimeString(); - 8:29:25 AM
DateTime.Now.ToLongDateString(); - Monday, September 17, 2007

--------------------------------------------------------------------------------

DateTime.Now.ToString("d"); - 9/17/2007
DateTime.Now.ToString("D"); - Monday, September 17, 2007
DateTime.Now.ToString("f"); - Monday, September 17, 2007 8:29 AM
DateTime.Now.ToString("F"); - Monday, September 17, 2007 8:29:25 AM
DateTime.Now.ToString("g"); - 9/17/2007 8:29 AM
DateTime.Now.ToString("G"); - 9/17/2007 8:29:25 AM
DateTime.Now.ToString("m"); - September 17
DateTime.Now.ToString("r"); - Mon, 17 Sep 2007 08:29:25 GMT
DateTime.Now.ToString("s"); - 2007-09-17T08:29:25
DateTime.Now.ToString("t"); - 8:29 AM
DateTime.Now.ToString("T"); - 8:29:25 AM
DateTime.Now.ToString("u"); - 2007-09-17 08:29:25Z
DateTime.Now.ToString("U"); - Monday, September 17, 2007 1:29:25 PM
DateTime.Now.ToString("y"); - September, 2007
DateTime.Now.ToString("dddd, MMMM dd yyyy"); - Monday, September 17 2007
DateTime.Now.ToString("ddd, MMM d "'"yy"); - Mon, Sep 17 '07
DateTime.Now.ToString("dddd, MMMM dd"); - Monday, September 17
DateTime.Now.ToString("M/yy"); - 9/07
DateTime.Now.ToString("dd-MM-yy"); - 17-09-07

No comments: