Day.js 中文文档

当前版本 v1.11

更多文档

月份名称

Locale#months 应该是月份名称的数组。

需要配合 UpdateLocale 插件才能工作

dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
  months: [
    "January", "February", "March", "April", "May", "June", "July",
    "August", "September", "October", "November", "December"
  ]
})

额外的令牌处理

如果你需要更多的处理来计算月份的名称,(例如,如果不同的格式有不同的语法),Locale#months 可以是一个具有以下签名的函数。它应该总是返回一个月份名称。

dayjs.updateLocale("en", {
  months: function (dayjsInstance, format) {
    // dayjsInstance is the Day.js object currently being formatted
    // format is the formatting string
    if (/^MMMM/.test(format)) {
      // if the format starts with 'MMMM'
      return monthShortFormat[dayjsInstance.month()];
    } else {
      return monthShortStandalone[dayjsInstance.month()];
    }
  },
});

Day.js 中文文档 - 粤ICP备14034220号-1