Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I want to get today date in dd/MM/yyyy format, but no matter what method I use, I still can't get the format I want.

 

txtDate.Text = Format(Now, "dd/MM/yyyy")

txtDate.Text = Now.ToString("dd/MM/yyyy")

txtDate.Text = Format(Today.Date, "dd/MM/yyyy")

 

I still get date in dd-MM-yyyy, example: 19-02-2004

 

If I move this application to other PC, it work fine. I just want to know which Windows setting affect the result?

  • *Experts*
Posted

If you use Now.ToString("dd/MM/yyyy") it should override any built in windows settings. I thought the Windows settings were only used for formats like "d" or "D". Can you double check that using the above doesn't work on some machines?

 

-nerseus

"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
Posted

Nerseus:

Last time I also thought like you. But now I can't explain why this thing happen.

 

HJB417:

I get the same result: 19-02-2004

 

The special about my PC is I am using Chinese version of Windows2000 Pro, but this function nothing to do with my Windows version right?

Posted (edited)

ok, what about this

 

const int enUS = 0x0409;
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(enUS); 
string data = DateTime.Now.ToString("dd/MM/yyyy", culture);

 

I'm still unsure but it probably has something to do with it being chinese. It states that "This method uses formatting information derived from the current culture.". On my machine, default is us, and it works correctly. If run the code above, and change the value of enUs to 0x0804 which is the code for Chinese - China, my results are the same as your first post. So it has to do w/ your culture code.

Edited by HJB417

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...