Search code examples
c++macoslocale

Why doesn't the locale change on OSX?


I'm trying to use strftime on a mac to output the time in a locale-dependent way.

I'm setting the locale and getting the time :

// sets the program's locale to the native locale
// without this line the locale is 'C'

log.debug(setlocale(LC_ALL,"")); 
struct tm* date = localtime(&time);
strftime(result.buf, size, "%X %x", date);
log.debug(result.buf);

which outputs

en_GB.UTF-8
13:58:01 25/10/2011

which is correct. However, I then go to the Language & Text System Preferences panel, and change the region to United States. If I run my program again, I get the same locale, and the time is formatted the same way (I'd expect the locale to be en_US and the date to be formatted 10/25/2011). What am I doing wrong?


Solution

  • You need to restart the terminal or whatever you're starting your program from for changes to take effect.