When de开发者_如何学编程signing a service that returns JSON to the browser (or server side JS), what is the "best" format for encoding dates in the resulting JSON response?
The data property should:
- require as little or no parsing to convert to a Date() object
- be sortable in the JSON representation itself
Returning the number of milliseconds since 1 January 1970 00:00:00 UTC seems like it would be the best option but is not particularly human readable when looking at the raw JSON.
What's preferred in your experience and why?
Personally I'd go with ISO 8601 (e.g. 2011-01-13T14:09Z).
It's well supported by virtually every programming language around, it's fairly easily human readable and, if you absolutely have to roll your own parser/formatter, it's fairly easy to deal with there too. It also has the sortable property you wanted.
精彩评论