{"id":4289,"date":"2014-11-05T09:00:36","date_gmt":"2014-11-05T11:00:36","guid":{"rendered":"http:\/\/blog.plataformatec.com.br\/?p=4289"},"modified":"2015-06-01T12:21:25","modified_gmt":"2015-06-01T15:21:25","slug":"how-to-serialize-date-and-datetime-without-losing-information","status":"publish","type":"post","link":"https:\/\/blog.plataformatec.com.br\/2014\/11\/how-to-serialize-date-and-datetime-without-losing-information\/","title":{"rendered":"How to serialize Date and DateTime to JSON without losing information"},"content":{"rendered":"

When building APIs, it is pretty common to use JSON as a serialization format. JSON defines serialization for boolean, number and string, but not for date\/datetime values.<\/p>\n

What most serializers do with Date and DateTime values is to use the ISO8601 standard. For example:<\/p>\n

\n# Date format\n2011-07-14\n\n# DateTime format\n2011-07-14T19:43:37+0100\n<\/pre>\n

However, you should be aware that information is lost when you use the Date format. That happens because a Date value might differ between different timezones. Let me give you an example:<\/p>\n