time.strptime() for different languages

Fredrik Lundh fredrik at pythonware.com
Wed Aug 31 17:54:56 EDT 2005


Adam Monsen wrote:

> No, this doesn't seem to work, and I can't find anything in the
> documentation indicating that it should.
>
> >>> import os
> >>> os.getenv('LANG')
> 'nl_NL'
> >>> import time
> >>> time.strptime("10 augustus 2005 om 17:26", "%d %B %Y om %H:%M")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/lib/python2.4/_strptime.py", line 292, in strptime
>     raise ValueError("time data did not match format:  data=%s  fmt=%s"
> %
> ValueError: time data did not match format:  data=10 augustus 2005 om
> 17:26  fmt=%d %B %Y om %H:%M

>>> import locale, time
>>> time.strftime("%B")
'August'
>>> locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_ALL, "")
'nl_NL'
>>> locale.getlocale()
('nl_NL', 'ISO8859-1')
>>> time.strftime("%B")
'augustus'
>>> time.strptime("10 augustus 2005 om 17:26", "%d %B %Y om %H:%M")
(2005, 8, 10, 17, 26, 0, 2, 222, -1)

(see http://docs.python.org/lib/module-locale.html for more on this)

</F>






More information about the Python-list mailing list