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

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -