views:

284

answers:

1

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.

+5  A: 

You can just set the locale like in this example:

>>> import time
>>> print time.strftime("%a, %d %b %Y %H:%M:%S")
Sun, 23 Oct 2005 20:38:56
>>> import locale
>>> locale.setlocale(locale.LC_TIME, "sv_SE") # swedish
'sv_SE'
>>> print time.strftime("%a, %d %b %Y %H:%M:%S")
sön, 23 okt 2005 20:39:15
mikl
BTW it won't work under Windows. Check this: http://stackoverflow.com/questions/955986/what-is-the-correct-way-to-set-pythons-locale/956084#956084
paffnucy
It also requires the computer you run this on to have the locale you are trying to use generated. On GNU/Linux systems, locale -a will give you the listing of the available locales. The steps for adding new locales differ between distros.
Joakim Lundborg