Getting Date and Time in certain format

a1jit

Regular
Joined
Aug 19, 2005
Messages
89
Hi Guys,

Im not sure why i cant get this done, Ijust want to retrieve two data
1) date (dd/mm/yyyy)
2) time (hh:mm:ss)

Im doing this two statements but its not only giving me the date..I dont know why i cant get it formatted..Any help will be really appreciated

System.DateTime.Now.ToShortDateString(),"dd/MM/yy"

Time is working as i want but not date

System.DateTime.Now.ToShortTimeString()
Thank You
 
If you want a guaranteed date format, you have to provide the string. For example:
date.ToString("dd/MM/yyyy hh:mm:ss")

If you want am/pm at the end, try:
date.ToString("dd/MM/yyyy hh:mm:ss tt")

There are other format strings available - check the MSDN documentation for Custom DateTime Format Strings.

Using ToShortDateString will get you a date formatted according to the OS's rules. You may abe able to override that with a custom DateTimeFormatInfo object, but I tend to prefer the custom string.

-ner
 
Back
Top