我有一个日期字符串:“Viernes 24 de Octubre”。我想将其更改为箭头日期时间对象。
我还安装了 es 语言环境: sudo apt-get install language-pack-es-base
这不起作用:
print arrow.get('Viernes 24 Octubre', 'dddd D MMMM', locale='es')
谢谢
最佳答案
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
注意:更改区域设置会影响整个程序。
关于Python 使用箭头更改区域设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26502470/