Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel date_format returning 2016 for 2017 date

I'm trying to display the date formatted for the specified language and I'm little surprised to see that:

babel.dates.format_date(date(2017,1,1), 'MMM Y')

gives the expected value which is:

u'Jan 2017'

while:

babel.dates.format_date(date(2017,1,1), 'MMM Y', locale='fr_FR')

gives me:

u'janv. 2016'

Why is it 2016 not 2017?

like image 362
aguyngueran Avatar asked Jan 24 '26 16:01

aguyngueran


1 Answers

This is because Y is giving you the week year. You need to use yyyy to get what you expect.

See https://github.com/python-babel/babel/issues/138

print format_date(date(2017,1,1), 'MMM yyyy')

print format_date(date(2017,1,1), 'MMM yyyy', locale='fr_FR')

Jan 2017
janv. 2017
like image 128
ScottSmudger Avatar answered Jan 27 '26 07:01

ScottSmudger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!