3 ms·
>But since there's no specification for the format to use, cross-browser date parsing is a mess Wrong! Since ECMAScript 5 there is a single, standard format th
by TazeTSchnitzel 13y ago
>But since there's no specification for the format to use, cross-browser date parsing is a mess
Wrong! Since ECMAScript 5 there is a single, standard format that all browsers will try to parse first and can predictably output: ISO 8601.
--
[02:49:29.621] (new Date()).toISOString()
[02:49:29.623] "2013-10-12T01:49:29.623Z"
--
[02:49:40.233] JSON.stringify(new Date())
[02:49:40.245] ""2013-10-12T01:49:40.246Z""
- curveship 13y agoNo, not all browsers, and not all of ISO 8601. Safari only added ISO 8601 Zulu parsing in the last few months, and IE only at version 9. Neither support explicit timezones yet. Which means there's still a large population of browsers that will choke. As I said, date parsing is a mess. In any case, my general point still stands: dates are the only "data" type (i.e. not a function, regex, etc.) which is not supported by JSON. So even if there were a usable universal serialization format, you'd still need to post-process the results of the JSON parser to convert the strings into dates.