python - Datetime's strftime formatting incorrectly -
i'm trying display date in brazilian locale dd/mm/yyyy. used datetime's srtftime("%x") function i'm getting mm/dd/yyyy. here's code used test it:
>>> import locale >>> import datetime dt >>> locale.getlocale() ('pt_br', 'cp1252') >>> today = dt.date.today() >>> today.strftime('%x') '10/07/13' it should 07/10/13.
i can with:
>>> today.strftime('%d/%m/%y') '07/10/13' but i'm wondering why didn't work in "correct" way.
when run locale.setlocale(category,locale) second parameter must recognizable, otherwise 'error: unsupported locale setting' error. can use:
print( locale.locale_alias) to dictionary of proper locale aliases, not of these locales have available. on windows machine it's 'portuguese_brazil' , for
locale.setlocale(locale.lc_all,'portuguese_brazil') today = dt.date.today() today.strftime('%x') print(today) output:
2013-10-07
Comments
Post a Comment