[英]Python change locale with arrow
I have a date string: "Viernes 24 de Octubre". 我有一个日期字符串:“ Viernes 24 de Octubre”。 I want to change it to arrow datetime object. 我想将其更改为箭头datetime对象。 also i have installed es locales: sudo apt-get install language-pack-es-base
This doesn't work: 我也已经安装了es语言环境: sudo apt-get install language-pack-es-base
这不起作用:
print arrow.get('Viernes 24 Octubre', 'dddd D MMMM', locale='es')
Thank you 谢谢
arrow.parser.DateTimeParser()
uses calendar.month_name[1:]
to parse month names ie, you need to set locale before calling arrow.get()
: arrow.parser.DateTimeParser()
使用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
Note: changing the locale affects the whole program. 注意:更改语言环境会影响整个程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.