Your problem is probably the fact that locale.nl_langinfo
doesn't appear to be available in Windows Python 2.7.x (I don't see it in my copy of Windows 64-bit Python 2.7.3). Looking at the docs at http://docs.python.org/2.7/library/locale.html#locale.nl_langinfo, they specifically say:
This function is not available on all systems, and the set of possible options might also vary across platforms.
Once you've set the locale up with something along the lines of:
locale.setlocale(locale.LC_ALL, 'english')
Then calls to some_date.strftime() will use correct locale specific formatting and strings. So if you want the date in string format, call some_date.strftime('%x')
replace the %x
with %X
for time or %c
for both. The full list of strftime formats are documented here.
>>> d = datetime.datetime.now()
... for loc in ('english', 'german', 'french'):
... locale.setlocale(locale.LC_ALL, loc)
... print loc, d.strftime('%c -- %x -- %X -- %B -- %A')
english 11/15/2012 4:10:56 PM -- 11/15/2012 -- 4:10:56 PM -- November -- Thursday
german 15.11.2012 16:10:56 -- 15.11.2012 -- 16:10:56 -- November -- Donnerstag
french 15/11/2012 16:10:56 -- 15/11/2012 -- 16:10:56 -- novembre -- jeudi
14: 'French_France.1252'