moment.js 格式化日期错误
moment.js formatting date wrong
我正在尝试使用 moment.js
获取即将到来的日期。获取了日期,但是格式错误。根据文档,format('l')
将日期格式化为 dd/mm/yyyy
格式,format('L')
将日期格式化为 mm/dd/yyyy
。但我得到的都是相同的输出。这是我的代码。
let next = moment().add(30, 'days').format('l'); // Output 10/16/2019
let next = moment().add(30, 'days').format('L'); // Output 10/16/2019
let next = moment().add(30, 'days').format('DD/MM/YYYY'); // Works fine
我试过 moment.js v2.24.0
这里有什么问题?我是漏掉了什么还是做错了什么?
According to docs, format('l')
formats the date in dd/mm/yyyy
format and format('L')
formats date in mm/dd/yyyy
.
不,那不是 the documentation says:
Localized formats
Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale.
There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.
Month numeral, day of month, year: L 09/04/1986
l 9/4/1986
没有什么可以说 L
将使用一个字段顺序而 l
将使用另一个字段顺序。
它正在使用您当前的 Moment 语言环境来设置日期格式。请参阅 i18n section 以了解如何全局或按实例设置语言环境。
根据文档
时刻().format('L'); // 2019/09/16
moment().format('l'); // 9/16/2019
我正在尝试使用 moment.js
获取即将到来的日期。获取了日期,但是格式错误。根据文档,format('l')
将日期格式化为 dd/mm/yyyy
格式,format('L')
将日期格式化为 mm/dd/yyyy
。但我得到的都是相同的输出。这是我的代码。
let next = moment().add(30, 'days').format('l'); // Output 10/16/2019
let next = moment().add(30, 'days').format('L'); // Output 10/16/2019
let next = moment().add(30, 'days').format('DD/MM/YYYY'); // Works fine
我试过 moment.js v2.24.0
这里有什么问题?我是漏掉了什么还是做错了什么?
According to docs,
format('l')
formats the date indd/mm/yyyy
format andformat('L')
formats date inmm/dd/yyyy
.
不,那不是 the documentation says:
Localized formats
Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale.
There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.
Month numeral, day of month, year: L 09/04/1986 l 9/4/1986
没有什么可以说 L
将使用一个字段顺序而 l
将使用另一个字段顺序。
它正在使用您当前的 Moment 语言环境来设置日期格式。请参阅 i18n section 以了解如何全局或按实例设置语言环境。
根据文档
时刻().format('L'); // 2019/09/16 moment().format('l'); // 9/16/2019