R. David Murray added the comment:
Yes, it is the default behavior, because the default locale, as for most
(almost all?) programming languages (not just Python), is the C locale, until
you change it. The reason for this is to get consistent behavior no matter
what the locale is set to, unles
Hugo Osvaldo Barrera added the comment:
The problem is that the datetime/strftime documentation describes "%c" as:
Locale’s appropriate date and time representation.
However, this is not really accurate (this is not the *default* behaviour),
that's why I was mentioning the clarification. I
Xiang Zhang added the comment:
I doubt the info belongs to datetime module documentation. When you encounter
locale related problems maybe it's better for you to refer locale module
documentation, and it mentions this behaviour
https://docs.python.org/3/library/locale.html#background-details-h
Hugo Osvaldo Barrera added the comment:
It would seem that
locale.setlocale(locale.LC_TIME, "")
fixes the issue. However, there seems to be no mention on this on the relevant
documentation page[1], which is actually the source of my confusion.
As a "fix" to this issue (since I'm probably
Eryk Sun added the comment:
As Martin said, you need to set the LC_TIME category using an empty string to
use the locale LC_* environment variables. Python 3 sets LC_CTYPE at startup
(on Unix platforms only), but LC_TIME is left in the initial C locale:
>>> locale.setlocale(locale.LC_CTYPE
Martin Panter added the comment:
>>> datetime.now().strftime("%x")
'02/06/17'
>>> from locale import setlocale, LC_TIME
>>> setlocale(LC_TIME)
'C'
>>> setlocale(LC_TIME, "en_US.utf8")
'en_US.utf8'
>>> datetime.now().strftime("%x")
'02/06/2017'
--
___
Martin Panter added the comment:
Have you tried enabling the locale with locale.setlocale()? I believe Python
only enables LC_CTYPE by default, so other locale aspects like LC_TIME won’t
work until they are enabled.
--
nosy: +martin.panter
___
Pytho
New submission from Hugo Osvaldo Barrera:
As the the posix spec for strftime:
%c The preferred date and time representation for the current locale.
%x The preferred date representation for the current locale without the time.
However, python doesn't seem to respect this:
$ python3.5 -c "fr