events (as a json feed), start end parameters unix timestamp, are different if I change my OS time zone

随声附和 提交于 2019-12-14 03:48:20

问题


I'm using the fullcalendar plugin and would appreciate if someone can give me a hand.

I am getting json events through a PHP URL. something like this:

$('#calendar').fullCalendar({ events: "/myfeed.php" });

So in my php page that returns the events, I am getting 3 GET parameters:

  • '_'
  • 'start'
  • 'end'

The start and end parameter, indicate the date in UNIX timestamp. So far so good, the problem that occurs is that if I change the time zone on my OS. also change these parameters start and end, for the same query in the same day in the calendar. the weirdest part is that it only happens in Mozilla Firefox. in Google Chrome, this problem does not occur.

e.g.

I have set my time zone ((UTC-04: 00) Santiago) I'm referring to the day 09.09.2012 on the agenda, firebug shows me that these parameters are being sent to my php page

  • _ 1347245953581
  • end 1347246000
  • start 1347159600

but if I change the time zone from my OS to ((UTC-03: 00) Buenos Aires) consulting on 09.09.2012 on the agenda, are other parameters which are now sent to the PHP page.

  • _ 1347246338047
  • end 1347332400
  • start 1347246000

Being that it is the same day, are other start and end parameters which are sent to check for events.


回答1:


There is an ignoreTimezone option on the fullcalendar that might help. I'm not sure if it affects the start/end time passed to the feeds.

http://arshaw.com/fullcalendar/docs/event_data/ignoreTimezone/

Another option is to convert the passed timestamp to a Date object and get the local data from the Date object afterwards and use that in your queries.

Convert a Unix timestamp to time in JavaScript

I know it is not the exact answer, but it might help you out a bit.

Here is a sample piece of PHP code to convert the passed timestamp into a local formatted date:

$startts = $_REQUEST["start"]; // original timestamp

$startdt = new DateTime('now', new DateTimeZone('Europe/Oslo') ); // setup a local datetime
$startdt->setTimestamp($startts); // Set the date based on timestamp

echo $startdt->format('Y-m-d H:i:s'); // Output local date and time


来源:https://stackoverflow.com/questions/12345020/events-as-a-json-feed-start-end-parameters-unix-timestamp-are-different-if-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!