Date time format in ASP.Net


Here are some custom formats of date time in ASP.Net:

 string date = DateTime.Now.Date; //This will show the Current Date

 
1) date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.Year.ToString()

Example it will shown as “Monday 18 October 2010 ”

 2) date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.ToString("HH:mm:ss")

It will show time as “Monday 18 October 21:00:13 ” with Hr format

 3) date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.ToString("hh:PM:mm:ss:tt")

It will show time as “Monday 18 October 21:00:13 PM” with Hr format with AM/PM

You also set format like this :-

DateTime.Now.ToString("MM/dd/yyyy");

DateTime.Now.ToString("MMM dd yyyy");

DateTime.Now.ToString("dd/MM/yyyy

0 comments: