Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...