Sunday, July 13, 2014

JSON Date Representation

When Javascript serialises an Date object in JSON, it will be represented in the following format:

2014-02-28T16:00:00.000Z

This means that when the user keys in a date on a web-form, and it gets submitted to the server, the exact time saved on the server contains time-zone information. In some applications, this may result in the date being off by 1 days when this date is subsequently used for processing, specifically in situations where you only really needed the date and not the time.

In the above example, it is actually 2014-03-01 in time-zone +0800. If the time is truncated, the processing will use 2014-02-28 instead.

If you want the date to be time-zone neutral, consider submitting the data to the server as a formatted date string of your choice.

No comments:

Post a Comment