Here are some examples of the different date format in c#, and You can customize this also as per your requirement. Hope it will help.
DateTime dt = DateTime.Now;
Response.Write(dt + ""); //output-1/16/2014 6:13:04 PM
Response.Write(String.Format("{0:y yy yyy yyyy}", dt) + ""); //output- 14 14 2014 2014
Response.Write(String.Format("{0:M MM MMM MMMM}", dt) + ""); //output- 1 01 Jan January
Response.Write(String.Format("{0:d dd ddd dddd}", dt) + "");//output- 16 16 Thu Thursday
Response.Write(String.Format("{0:h hh H HH}", dt) + "");//output- 5 05 17 17
Response.Write(String.Format("{0:m mm}", dt) + ""); //output- 55 55
Response.Write(String.Format("{0:s ss}", dt) + ""); //output- 31 31
Response.Write(String.Format("{0:f ff fff ffff}", dt) + "");//output- 5 50 502 5022
Response.Write(String.Format("{0:F FF FFF FFFF}", dt) + "");//output- 5 5 502 5022
Response.Write(String.Format("{0:t tt}", dt) + "");//output- P PM
Response.Write(String.Format("{0:z zz zzz}", dt) + "");//output- +5 +05 +05:30
Response.Write(String.Format("{0:d/M/yyyy HH:mm:ss}", dt) + "");//output- 16/1/2014 17:55:31
Response.Write(String.Format("{0:d/M/yyyy HH:mm:ss}", dt) + "");//output-16/1/2014 17:55:31
Response.Write(String.Format("{0:M/d/yyyy}", dt) + "");//output- 1/16/2014
Response.Write(String.Format("{0:MM/dd/yyyy}", dt) + "");//output- 01/16/2014
Response.Write(String.Format("{0:ddd, MMM d, yyyy}", dt) + "");//output- Thu, Jan 16, 2014
Response.Write(String.Format("{0:dddd, MMMM d, yyyy}", dt) + "");//output- Thursday, January 16, 2014
Response.Write(String.Format("{0:MM/dd/yy}", dt) + "");//output- 01/16/14
Response.Write(String.Format("{0:MM/dd/yyyy}", dt) + "");//output- 01/16/2014
Response.Write(String.Format("{0:t}", dt) + "");//output- 5:55 PM
Response.Write(String.Format("{0:d}", dt) + "");//output- 1/16/2014
Response.Write(String.Format("{0:T}", dt) + "");//output- 5:55:31 PM
Response.Write(String.Format("{0:D}", dt) + "");//output- Thursday, January 16, 2014
Response.Write(String.Format("{0:f}", dt) + "");//output- Thursday, January 16, 2014 5:55 PM
Response.Write(String.Format("{0:F}", dt) + "");//output- Thursday, January 16, 2014 5:55:31 PM
Response.Write(String.Format("{0:g}", dt) + "");//output- 1/16/2014 5:55 PM
Response.Write(String.Format("{0:G}", dt) + "");//output- 1/16/2014 5:55:31 PM
Response.Write(String.Format("{0:m}", dt) + "");//output- January 16
Response.Write(String.Format("{0:y}", dt) + "");//output- January, 2014
Response.Write(String.Format("{0:r}", dt) + "");//output- Thu, 16 Jan 2014 17:55:31 GMT
Response.Write(String.Format("{0:s}", dt) + "");//output- 2014-01-16T17:55:31
Response.Write(String.Format("{0:u}", dt) + "");//output- 2014-01-16 17:55:31Z
No comments:
Post a Comment