我正在尝试更改moment.js设置的日期的语言。默认是英语,但我想设置德语。以下是我的尝试:

var now = moment().format("LLL").lang("de");

它会产生NaN。

var now = moment("de").format("LLL");

这甚至不是反应。

var now = moment().format("LLL", "de");

没有变化:这仍然是用英语生成的结果。

这怎么可能呢?


当前回答

对于momentjs 2.12+,执行以下操作:

moment.updateLocale('de');

还要注意,你必须使用moment。updateLocale(localeName, config)来更改现有的语言环境。moment.defineLocale(localeName, config)应该只用于创建一个新的区域设置。

其他回答

我使用的是angular2-moment,但用法必须相似。

import { MomentModule } from "angular2-moment";
import moment = require("moment");

export class AppModule {

  constructor() {
    moment.locale('ru');
  }
}

根据版本更改moment js语言

版本:2 + 8。

moment.locale('嗨');

版本:2.5.1

moment.lang('嗨');

在2.18.1秒之后:

  moment.locale("de");
  var m = moment().format("LLL")

哎呀,笔误。我会解决这个问题: Var矩=函数(x){返回矩(x).locale('de');其他方法在某些条件下(对我来说)似乎不太管用。

我不知道发生了什么变化,但像这样导入语言文件对我有用

import 'moment/src/locale/fr';
moment.locale('fr')

注意import语句中的src