我正在尝试更改由 moment.js 设置的日期的语言。默认的是英语,但我想设置德语。这些是我尝试过的:
var now = moment().format("LLL").lang("de");
它给了 NaN
。
var now = moment("de").format("LLL");
这甚至没有反应。
var now = moment().format("LLL", "de");
没有变化:这仍然会产生英语结果。
这怎么可能?
原文由 doniyor 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要 moment.lang ( 警告:
lang()
自 moment2.8.0
起已弃用,请改用locale()
):http://momentjs.com/docs/#/i18n/
从 v2.8.1 开始,
moment.locale('de')
设置本地化,但不返回moment
。一些例子:总之,在全局
moment
上调用locale
会为所有未来的moment
实例设置 locale,但不会返回moment
的实例。在实例上调用locale
,为该实例设置它并返回该实例。此外,正如 Shiv 在评论中所说,请确保使用“moment-with-locales.min.js”而不是“moment.min.js”,否则将无法正常工作。