Python用箭头改变语言环境

时间:2014-10-22 07:41:18

标签: python string datetime arrow-python

我有一个日期字符串:" Viernes 24 de Octubre"。我想将其更改为箭头日期时间对象。 我也安装了es locales:sudo apt-get install language-pack-es-base 这不起作用:

print arrow.get('Viernes 24 Octubre', 'dddd D MMMM', locale='es')

谢谢

1 个答案:

答案 0 :(得分:1)

arrow.parser.DateTimeParser() uses calendar.month_name[1:]解析月份名称,即您需要在调用arrow.get()之前设置区域设置:

import calendar
import locale

print(calendar.month_name[10])
# -> October
locale.setlocale(locale.LC_TIME, 'es_ES.UTF-8') # system-dependent locale name
print(calendar.month_name[10])
# -> Octubre

注意:更改区域设置会影响整个程序。