Loading ...

How can get the system date and system time (separately) | CodeAsp.Net

How can get the system date and system time (separately)

 /5
0 (0votes)

Here I discuss the different formats of datetime. most of us facing this format relating issues during

work with datetime. so these format may help u to display the date time format as we want .

and it also help to reduce chances of exception.

To get the system date and time separately in c# .just use the

for date only:

DateTime.Now.ToShortDateString();

for timeonly:
DateTime.Now.ToShortTimeString();

To get the date  in Sat, November 28, 2009 format simply do as following:

Response.Write(DateTime.Now.ToString("0:ddd, MMMM dd, yyyy"));

To get the time  in 24 hour format simply do as following:

Response.Write(DateTime.Now.ToString("HH:mm ss tt"));

To get the time  in 12 hour format simply do as following:

Response.Write(DateTime.Now.ToString("hh:mm ss tt"));

 

Hope this will help...

 

 

Comments (no comments yet)

Top Posts