Python使用更改区域设置

2024-10-03 17:17:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个日期字符串:“viernes24deoctubre”。我想把它改成arrow datetime对象。 我还安装了es语言环境:sudo apt-get install language-pack-es-base 这不起作用:

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

谢谢你


Tags: install对象字符串语言basegetdatetime环境
1条回答
网友
1楼 · 发布于 2024-10-03 17:17:15

^{} uses ^{}要解析月份名称,即在调用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

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

相关问题 更多 >