Python 使用箭头更改区域设置

标签 python string datetime arrow-python

我有一个日期字符串:“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/

相关文章:

java - 约会的数据模型 - 选择多个日期

python - 从循环中的字符串列表创建新的列名称

python - 我尝试用另一个定义中的另一个字典迭代嵌套字典,但 Django 不渲染它

c# - 如何概括我的算法以检测一个字符串是否是另一个字符串的旋转

java - Hibernate 将默认日期时间插入非空列

c# - 是否可以减少 DateTime.Now.Ticks.ToString ("X"的长度)并仍然保持唯一性?

python - 使用 .format 格式化字符串时检索预期的键名

Python:将字符串存储到数组中似乎会移动字符串索引?

c# - C# 中 string.Empty 和 String.Empty 的区别

c# - 如何通过删除字符串的非字母来计算词频?