Search code examples
jqueryfullcalendarunix-timestamp

JQuery fullCalendar: problem with date/event - It's rendering an hour too late!


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.


Solution

  • 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.

    $startTimestamp = 1303776000; //2011-04-26 at 12am
    $startISO = date('c', $startTimestamp);
    echo $startISO; //Outputs 2011-04-26T00:00:00+00:00
    

    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!