日历时间
日历时间显示相对于给定参考时间(默认为现在)的时间,但与 dayjs#fromNow
略有不同。
¥Calendar time displays time relative to a given reference time (defaults to now) but does so slightly differently than dayjs#fromNow
.
This requires the
Calendar
plugin to work
dayjs.extend(calendar)
dayjs().calendar()
dayjs().calendar(dayjs('2008-01-01'))
键 | 值 |
---|---|
上周(上周) | Last Monday at 2:30 AM |
前一天(最后一天) | Yesterday at 2:30 AM |
The same day (sameDay) | Today at 2:30 AM |
The next day (nextDay) | Tomorrow at 2:30 AM |
The next week (nextWeek) | Sunday at 2:30 AM |
Everything else (sameElse) | 7/10/2011 |
这些字符串是本地化的,并且是 可以定制。
¥These strings are localized, and can be customized.
你还可以将指定的日历输出格式作为第二个参数传递。
¥You can also pass specifying calendar output formats as the second parameter.
要转义字符,请将它们括在方括号中(例如 [Today])。
¥To escape characters, wrap them in square brackets (e.g. [Today]).
dayjs().calendar(null, {
sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM )
nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM )
nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM )
lastDay: '[Yesterday]', // The day before ( Yesterday at 2:30 AM )
lastWeek: '[Last] dddd', // Last week ( Last Monday at 2:30 AM )
sameElse: 'DD/MM/YYYY' // Everything else ( 7/10/2011 )
})