Localized strftime()

Fredrik Lundh fredrik at pythonware.com
Sun Oct 23 14:41:14 EDT 2005


Sebastjan Trepca wrote:

> I'm trying to get a localized date format from strftime() but it seems
> that is doesn't have any parameters for that or any information about
> this issue in Python docs.
>
> For example I want to turn this:
> 19 Oct, 2005
> to this(slovene language):
> 19 Okt, 2005

you must call locale.setlocale first, to switch from the default C
locale to a locale of your choice.

    http://docs.python.org/lib/module-locale.html

>>> 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
>>> locale.setlocale(locale.LC_TIME, "sl_SI")
'sl_SI'
>>> print time.strftime("%a, %d %b %Y %H:%M:%S")
ned, 23 okt 2005 20:39:32

</F>






More information about the Python-list mailing list