簡體   English   中英

Python用箭頭更改語言環境

[英]Python change locale with arrow

我有一個日期字符串:“ Viernes 24 de Octubre”。 我想將其更改為箭頭datetime對象。 我也已經安裝了es語言環境: sudo apt-get install language-pack-es-base這不起作用:

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

謝謝

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

注意:更改語言環境會影響整個程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM