1

我正在尝试在我的工作项目中替换 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 格式

4

1 回答 1

0

这应该有效:

dayjs.tz(created_at, tzIdentifier).calendar(dayjs.tz(tzIdentifier), calendar_options)

于 2021-06-10T16:02:51.497 回答