How do I get datetime.datetime.now()
printed out in the native language?
>>> session.deathDate.strftime("%a, %d %b %Y")
'Fri, 12 Jun 2009'
I'd like to get the same result but in local language.
How do I get datetime.datetime.now()
printed out in the native language?
>>> session.deathDate.strftime("%a, %d %b %Y")
'Fri, 12 Jun 2009'
I'd like to get the same result but in local language.
You can just set the locale like in this example:
You should use
%x
and%X
to format the date string in the correct locale. E.g. in Swedish a date is represented as2014-11-14
instead of11/14/2014
.The correct way to get the result as Unicode is:
Here is the result from multiple languages:
Another option is:
solution for russian language and cross platform
If your application is supposed to support more than one locale then getting localized format of date/time by changing locale (by means of
locale.setlocale()
) is discouraged. For explanation why it's a bad idea see Alex Martelli's answer to the the question Using Python locale or equivalent in web applications? (basically locale is global and affects whole application so changing it might change behavior of other parts of application)You can do it cleanly using Babel package like this:
See Date and Time section in Babel's documentation.