$ locale LANG=ja_JP.UTF-8 LANGUAGE=ja_JP:ja:en_GB:en LC_CTYPE="ja_JP.UTF-8" LC_NUMERIC="ja_JP.UTF-8" LC_TIME="ja_JP.UTF-8" LC_COLLATE="ja_JP.UTF-8" LC_MONETARY="ja_JP.UTF-8" LC_MESSAGES="ja_JP.UTF-8" LC_PAPER="ja_JP.UTF-8" LC_NAME="ja_JP.UTF-8" LC_ADDRESS="ja_JP.UTF-8" LC_TELEPHONE="ja_JP.UTF-8" LC_MEASUREMENT="ja_JP.UTF-8" LC_IDENTIFICATION="ja_JP.UTF-8" LC_ALL=
locale.setlocale() ありの場合:
$ python
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'ja_JP.UTF-8'
>>> import time
>>> time.strftime("%b")
' 4\xe6\x9c\x88'
>>> print time.strftime("%b")
4月
>>> print time.strptime(u" 4月".encode('utf-8'), "%b")
time.struct_time(tm_year=1900, tm_mon=4, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=91, tm_isdst=-1)
>>> time.strptime("Apr", "%b")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'Apr' does not match format '%b'
locale.setlocale() なしの場合:
$ python
>>> import time
>>> time.strftime("%b")
'Apr'
>>> time.strptime("Apr", "%b")
time.struct_time(tm_year=1900, tm_mon=4, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=91, tm_isdst=-1)
>>> time.strptime(u" 4月".encode('utf-8'), "%b")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data ' 4\xe6\x9c\x88' does not match format '%b'