教程 dayjs tutorial

Calendar

Locale#calendar 应该包含以下内容。

这依赖 UpdateLocale 插件,才能正常运行

javascript
dayjs.extend(updateLocale);

dayjs.updateLocale("en", {
  calendar: {
    lastDay: "[Yesterday at] LT",
    sameDay: "[Today at] LT",
    nextDay: "[Tomorrow at] LT",
    lastWeek: "[last] dddd [at] LT",
    nextWeek: "dddd [at] LT",
    sameElse: "L",
  },
});

每个 Locale#calendar 的键值也可以是一个函数,这个函数的作用域是当前 Day.js 对象,且传入的第一个参数是代表当天的 Day.js 对象。 这个函数需要返回一个格式化后的字符串。

javascript
function callback(now) {
  return "[hoy a la" + (this.hour() !== 1 ? "s" : "") + "]" + now.format();
}