angularjs - mattlewis92/angular-bootstrap-calendar 在不同时区计算错误日期

标签 angularjs datetime timezone momentjs angular-bootstrap-calendar

我正在使用这个日历 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;

附上截图:

[截图]

enter image description here

你可以看到用户当前的时区是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/

相关文章:

javascript - 如何自定义 Angular/Bootstrap 模式转换

ruby-on-rails - 在 DateTime 减法中返回分钟

angularjs - polymer 和 Angular 一起使用

angularjs - ng-show 和 ng-if 滞后于隐藏内容

python - pd.read_csv(parse_dates... [date_formatter=]) 返回 dtype 'object' 而不是 'datetime64'

java - 在 Java 中覆盖系统属性(无代码)

python - Django 在模板中获取用户时区

java - 是否可以创建像 Tue Mar 03 13 :43:00 (without time zone)? 这样的 Calendar 对象

javascript - 如何在 angularjs 应用程序中注销时删除/清除存储在范围变量中的数据?

c# 解析 json 日期?