# Month Names

URL: https://caijiao.org/dayjs/customization/month-names
Source: docs/dayjs/customization/month-names.md
Description: 月份名称在 Day.js 中通过 Locale#months 数组进行定义。用户可以使用 UpdateLocale 插件自定义月份名称。若需要更高级的占位符处理，可将 Locale#months 定义为一个函数来实现。

`Locale#months` 应该是一个包含月份的数组。



```javascript
dayjs.extend(updateLocale);

dayjs.updateLocale("en", {
  months: [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
  ],
});
```

## 更高级的占位符处理

如果需要更多处理来计算月份的名称（例如，如果不同格式的语法不同），则 `Locale#months` 可以是具有以下签名的函数。 它应始终返回月份的名称。

```javascript
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()];
    }
  },
});
```
