JQuery fullCalendar:日期/事件问题 - 渲染晚了一个小时!
我刚刚在 fullCalendar 实现中发现了一些奇怪的地方。
基本上,我在数据库中有一个日期“28/04/2011 09:00:00”(dmy),我将其转换为 Unix 时间戳,结果为 1303981200.0。
我已经检查过 http://www.onlineconversion.com/unix_time.htm,并且时间戳有效。
但是,当我将此 JSON 传递到 fullCalendar 时,它会在一小时后呈现该事件!
JSON 是:
[{"id":"4a315750666d2f70675241544936762b632f514f51513d3d","title":"Blah blah blah","description":"","start":1303981200,"end":1303983000,"className":"A-16","allDay":false}]
困惑
谢谢。
I have a bit of wierdness that I've just spotted inside my fullCalendar implementation.
Basically, I have a date inside the database "28/04/2011 09:00:00" (dmy), which I convert into a Unix Timestamp, which results in 1303981200.0.
I've checked with http://www.onlineconversion.com/unix_time.htm, and the timestamp is valid.
However, when I pass this JSON into fullCalendar, it renders the event an hour later!
The JSON is:
[{"id":"4a315750666d2f70675241544936762b632f514f51513d3d","title":"Blah blah blah","description":"","start":1303981200,"end":1303983000,"className":"A-16","allDay":false}]
Baffled
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嘿 amit_g,我也使用 php 生成的时间戳遇到了这个问题。出现此问题的原因是时间戳并不“字面上”包含时区,因此当 FC 通过 JavaScript 使用 Date() 对其进行转换时,将使用您的本地时区。
我通过在向 FC 提供事件时简单地使用完整的 ISO 8601 日期格式而不是时间戳来解决这个问题。
在事件开始时仅向 FC 提供 $startTimestamp 会根据我的时区(由于夏令时,当时为 -4 EST)显示事件,因为时间戳为上午 12 点,javascript Date() 减去 4 小时,因此显示我的事件一整天早些时候在FC上。现在使用 ISO 日期可以在正确的时间显示我的所有事件。希望这对其他人有帮助!
Hey amit_g, I also ran into this using timestamps generated by php. The issue occurs because a timestamp does not 'literally' contain a timezone, so when it's converted by javascript with Date() by FC your local timezone is used.
I solved this by simply using the full ISO 8601 date format instead of a timestamp when supplying events to FC.
Supplying FC with just $startTimestamp as the event start displays the event according to my timezone (-4 EST at the time due to DST) since the timestamp is for 12am, javascript Date() subtracts 4 hours, hence showing my event a full day earlier on FC. Using the ISO date now shows all my events at the correct time. Hope this helps someone else!
您可能必须尝试添加时区位置,因为您的服务器可能有不同的时间。
http://arshaw.com/fullcalendar/docs/event_data/ignoreTimezone/
You might have to try and add timezone locations as your server could have different times.
http://arshaw.com/fullcalendar/docs/event_data/ignoreTimezone/
这个时间差异可能是由于夏令时造成的。 Fullcalendar 代码可能被设置为当前客户端的时间;您可能需要根据时区和夏令时差异进行调整。请参阅 FullCalendar 文档中的时区陷阱。不太有帮助,但可能会为您指明正确的方向。
It's likely this hour discrepency is due to daylight savings time. The Fullcalendar code is probably being set to the current client's time; you may have to adjust for timezone and daylight savings differences. See Timezones Gotchas in FullCalendar documentation. Not overly helpful, but may point you in the right direction.