我正在使用这个日历 https://github.com/mattlewis92/angular-bootstrap-calendar为世界各地的人们展示事件和时间段。在注册期间,每个用户都必须设置他的时区,然后我的应用程序使用这个时区进行进一步的日期计算,而不是客户端机器时区。
问题是,当我使用 moment.tz.setDefault(timezone)
将用户时区设置为默认时区并更改机器的时区时,日历会错误地计算日期。
这是我的代码摘录:
moment.tz.setDefault($rootScope.timezone)
vm.calendarView = 'month';
vm.viewDate = moment().startOf('month').toDate();
vm.cellIsOpen = true;
附上截图:
[截图]
你可以看到用户当前的时区是Asia/Karachi +5,而我机器的时区是北京+8。今天的日期是 9 月 8 日,那天是星期五,但在日历上,9 月 8 日显示为星期六而不是星期五。
最佳答案
mwl-calander 没有提供timezone 的支持,你可以使用full calander
https://fullcalendar.io/ 演示 https://fullcalendar.io/js/fullcalendar-2.9.1/demos/timezones.html
它的 Angular 指令可以在 https://github.com/angular-ui/ui-calendar
关于angularjs - mattlewis92/angular-bootstrap-calendar 在不同时区计算错误日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46116669/