【问题标题】:Babel date_format returning 2016 for 2017 dateBabel date_format 为 2017 日期返回 2016
【发布时间】:2017-02-05 17:56:07
【问题描述】:

我正在尝试显示为指定语言格式化的日期,但看到这一点我并不感到惊讶:

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

给出的期望值是:

u'Jan 2017'

同时:

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

给我:

u'janv. 2016'

为什么是 2016 年而不是 2017 年?

【问题讨论】:

  • 您的确切问题是什么?
  • 有什么问题?至于缩写月份,据我们可怜的池塘边的人说,janv. 是 1 月正确的法语缩写月份格式 (lts.library.cornell.edu/lts/pp/spp/mosabbr#french)。
  • 是的,但应该是 2017 年而不是 2016 年 :)

标签: python python-babel


【解决方案1】:

这是因为Y 给你一周年。您需要使用yyyy 来获得您所期望的。

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

【讨论】:

猜你喜欢
  • 2017-03-13
  • 1970-01-01
  • 2019-11-05
  • 1970-01-01
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
相关资源
最近更新 更多