Date/time formats accepted by fullCalendar events

To render fullCalendar events the date format is very important. Since version 2.0 `fullCalendar` depends on the awesome MomentJS library.  The dates a `moment` object understands by default are in the ISO 8601 format. If they are not, MomentJS falls back to a regular JavaScript Date object, but it  issues a warning that the fall back could be removed in the future.

So, it is always recommended to use the ISO 8601 format in the  event objects we feed `fullCalendar`.  For dates use “YYYY-MM-DD” and for combined date and time use one of these: “YYYY-MM-DD hh:mm:ss” or “YYYY-MM-DDThh:mm:ss“, where a space or the letter “T” separates the time from the date. The time uses the 24-hour clock format.

One of the common mistakes when formatting dates for `fullCalendar` is forgetting to zero-pad the numbers, in the date or time.  This is a valid date: “2016-01-04 08:30:00“, but not this one “2016-1-4 8:30:00” because some numbers are not zero-padded.  Some times finding this bug is like searching for a sneaky semicolon in JavaScript code.

When the events are generated by a server side application you must take care of correctly formatting the `start` and `end` dates and times.  For example, in Python we will always use this formatting strings: “%Y-%m-%d” for dates and “%Y%m-%d %H:%M:%S” for date and time.

I should mention that MomentJS is very capable of parsing almost any reasonable date/time string, but I think we should take responsibility for returning what it expects by default. Of course, this will not always be possible, specially if we do not have control of the application generating the events.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s