简体   繁体   中英

Python change locale with arrow

I have a date string: "Viernes 24 de Octubre". I want to change it to arrow datetime object. also i have installed es locales: sudo apt-get install language-pack-es-base This doesn't work:

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() :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM