Date Format again...

bungpeng

Well-known member
Joined
Sep 10, 2002
Messages
906
Location
Malaysia
I want to get today date in dd/MM/yyyy format, but no matter what method I use, I still cant 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?
 
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 doesnt work on some machines?

-nerseus
 
run this on your machine(s) and tell me what is the value of the variable data

string data = DateTime.Now.ToString("dd/MM/yyyy");
 
Nerseus:
Last time I also thought like you. But now I cant 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?
 
ok, what about this

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

Im 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.
 
Last edited by a moderator:
Back
Top