Re: strftime not displaying date in correct locale
- From: Norbert Unterberg <nunterberg@xxxxxxxxxxxxxxxxx>
- Date: Thu, 10 Jul 2008 21:29:29 +0200
Herby schrieb:
[...]I am expecting to get the date in UK format via the following code:
String DateTime::ToString()const
To switch the C runtime to a different locale, use the setlocale()
function. To switch to the current user's locale, use something like:
setlocale(LC_ALL, "");
or at least use
setlocale(LC_TIME, "");
to switch the locale for time conversions.
Thanks Norbert for that nugget of info. It works now.
I was onto that but had used setlocale(LC_ALL, NULL) which made no
difference.
One word of warning:
Using setlocale(LC_ALL, ""); can have unexpected side effects.
On a German windows system, it switches the decimal point to a decimal comma (as we Germany write 1234,56 instead of 1234.56. So if you put setlocale(LC_ALL, "") into an application that writes and reads numerical values into a text file or from a text file, then the application can no longer read the data it has written when the user changes the locale in control panel.
So you should be careful to switch back to the "C" locale when storing numbers or dates in a text file.
Norbert
.
- References:
- strftime not displaying date in correct locale
- From: Herby
- Re: strftime not displaying date in correct locale
- From: Norbert Unterberg
- Re: strftime not displaying date in correct locale
- From: Herby
- strftime not displaying date in correct locale
- Prev by Date: Re: max size of ptr array
- Next by Date: Re: assembly code for release code?
- Previous by thread: Re: strftime not displaying date in correct locale
- Next by thread: Array of structs with variable length strings.
- Index(es):
Relevant Pages
|