Monday, September 29, 2008

DateTime Format Strings


Been googling about common DateTime format strings.
Surprisingly, very few relevant ones came up.
So decided to make a post of the formats I got for future reference



DateTime.Now; //5/16/2006 1:05:13 AM
DateTime.Now.ToString(); //5/16/2006 1:05:13 AM
DateTime.Now.ToShortTimeString() //11:40 AM
DateTime.Now.ToShortDateString() //5/16/2006
DateTime.Now.ToLongTimeString() //11:40:13 AM
DateTime.Now.ToLongDateString() //Tuesday, May 16, 2006



Examples of DateTime for Given Formats



DateTime.Now.ToString("dddd, MMMM dd yyyy") // Tuesday, May 16 2006
DateTime.Now.ToString("ddd, MMM d "'"yy") // Tue, May 16 '06
DateTime.Now.ToString("dddd, MMMM dd") // Tuesday, May 16
DateTime.Now.ToString("M/yy") // 5/06
DateTime.Now.ToString("dd-MM-yy") // 16-05-06



Courtesy : An article from DOTNET Spider

Related Posts :



0 comments on "DateTime Format Strings"

Add your comment. Please don't spam!
Subscribe in a Reader

Post a Comment