问题描述
我正在尝试替换我的工作项目中的 moment.js,最近遇到了一个问题, 这是一个返回错误输出的代码
const created_at = '2020-12-23T07:28:19Z'; // today is december 30th
const tzIdentifier = 'Asia/Novosibirsk';
const calendar_options = {
sameDay: '[Today at] h:mm A',nextDay: '[Tomorrow at] h:mm A',nextWeek: 'dddd [at] h:mm A',lastDay: '[Yesterday at] h:mm A',lastWeek: '[Last] dddd [at] h:mm A',sameElse: 'DD/MM/YYYY'
}
day(created_at).tz(tzIdentifier).calendar(null,calendar_options); // always returns sameElse but there should be lastWeek
时区没有区别,因为 day(created_at).calendar(null,calendar_options);
仍然返回 sameElse 格式
解决方法
这应该有效:
dayjs.tz(created_at,tzIdentifier).calendar(dayjs.tz(tzIdentifier),calendar_options)