问题
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