月の名前
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()];
}
},
});