Re: strftime not displaying date in correct locale

Tech-Archive recommends: Speed Up your PC by fixing your registry





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
.



Relevant Pages

  • Regional Settings
    ... I have a custom shell that has English, German and Chinese languages. ... into the registry and the font substitutes where non-existent. ... problem stems from when I switch the system locale to Chinese the ... I tried setting the locale manually with the Intl.cpl and it shows me ...
    (microsoft.public.windowsxp.embedded)
  • can one prevent XP from switching the keyboard layout?
    ... I occasionally have to switch my locale (i.e. language and location ... What's starting to drive me nuts is, ... Can one somehow tell XP to LEAVE MY KEYBOARD LAYOUT UNTOUCHED, ...
    (microsoft.public.windowsxp.customize)
  • Re: strftime not displaying date in correct locale
    ... It keeps diplaying in US format even though on my windows OS it is set ... The C library functions do not automatically follow the windows locale. ... To switch the C runtime to a different locale, ...
    (microsoft.public.vc.language)
  • Re: ofstream
    ... system decimal point character. ... You can switch the whole program to C locale, ... just writing to this stream. ... If output to that text file is isolated, you can also switch to C locale ...
    (microsoft.public.vc.language)
  • Re: strftime not displaying date in correct locale
    ...  If i go into regional settings via control panel, ... The C library functions do not automatically follow the windows locale. ... To switch the C runtime to a different locale, ...
    (microsoft.public.vc.language)