The "right" JSON Date Format

This translation from: at The "right" JSON format DATE

I've seen so many different standards for the JSON date format: I have seen many different standard JSON Date format:

"\"\\/Date(1335205592410)\\/\""         .NET JavaScriptSerializer
"\"\\/Date(1335205592410-0500)\\/\""    .NET DataContractJsonSerializer
"2012-04-23T18:25:43.511Z"              JavaScript built-in JSON object
"2012-04-21T18:25:43-05:00"             ISO 8601

Which one is the right one? Which one is correct? Or best? Or the best? Is there any sort of standard on this ? What are standards?


#1st Floor

Reference: https://stackoom.com/question/h9uW/ correct date format -JSON


#2nd Floor

Anything does not know the About JSON a dates. JSON to date nothing. A non IS .NET does what Standard-hack / Extension. .NET done nonstandard hack / extension.

Would A format that use the I CAN BE A Easily Converted to DateObject in JavaScript, IE One CAN BE passed to that new Date(...). I will use a JavaScript can be easily converted to a Dateformat object that can be passed to new Date(...)the format. The easiest and probably most portable format is the timestamp containing milliseconds since 1970. The easiest and perhaps most portable format since 1970 include millisecond timestamp.


#3rd floor

There IS NO right format ; not in the correct format ; at The JSON Specification . Does not the Specify A format for Exchanging a dates Which IS Why there are SO MANY Different Ways to do IT JSON specification does not format exchange date is specified, which is why there are so many different ways to achieve the reasons.

Best format. Arguably IS A at The DATE Represented in ISO 8601 format ( See Wikipedia ); best format can say is ISO 8601 format date indicated ( See Wikipedia ). it is a well known and widely used format and can be handled across many different languages, making it very well suited for interoperability. It is a well known and widely used format, and can be processed in many different languages, making it ideal for interoperability. If you have control over the generated json , for example, you provide data to other systems in json format, choosing 8601 as the date interchange format is a good choice. For example, if you can control json generated may json format data available to other systems, choosing 8601 as the date interchange format is a good choice.

If you do not have control over the generated json, for example, you are the consumer of json from several different existing systems, the best way of handling this is to have a date parsing utility function to handle the different formats expected. For example, if You can not control the generation of json, then you are a user of several existing systems json, then the best way to handle this problem is to use date parsing utility functions to handle the different formats required.


#4th floor

JSON Itself does not the Specify How Should a dates BE Represented, But JavaScript does. JSON itself does not specify how the date should be expressed, but JavaScript has specified.

By You Should use at The format Emitted by Date'S toJSONMethod,: You should use Datethe toJSONformat issued by the method:

2012-04-23T18:25:43.511Z

Here's why: the following reasons:

  1. It's human readable but also succinct that it is human-readable but also very simple

  2. It sorts correctly sorted correctly

  3. It includes fractional seconds, which can help re-establish chronology includes fractional seconds, can help re-establish order in time

  4. It conforms to ISO 8601 符合ISO 8601

  5. Well-8601 has been ISO Internationally for the ESTABLISHED More Within last A Decade ISO 8601 has established more than a decade in the international

  6. IS endorsed by ISO 8601 the W3C , RFC3339 , and XKCD the W3C , RFC3339 and XKCD recognized ISO 8601

Being of Said That , Every DATE Library Ever written CAN Understand "Operating since 1970 milliseconds." That being said , each date library can understand "Since 1970 the number of milliseconds." For the Easy Portability SO, ThiefMaster IS right. Therefore, for easy to carry, ThiefMaster is correct.


#5th Floor

The From the RFC 7493 (the Format of The the I-the JSON the Message) : From RFC 7493 (I-JSON format message) begins :

JSON-Stands for either the I Internet JSON or the Interoperable JSON, you DEPENDING ON the WHO ASK. The I-JSON Internet JSON or on behalf of interoperable JSON, depending on how you ask.

Protocols often contain data items that are designed to contain timestamps or time durations. Protocols typically contains data items intended to contain a timestamp or duration. IT IS RECOMMENDED that All SUCH the Data items BE Expressed AS String values in ISO 8601 format, AS specified in RFC 3339 , with at The Additional Restrictions that UPPERCASE The Rather Within last lowercase Letters BE Used, that at The TimeZone BE included not Defaulted, and that optional trailing seconds The be included even when their value is " 00". recommends that all such items are in accordance with the 3339 RFC string representation of the value of ISO 8601 format requirements and have other limitations, namely the use of uppercase and lowercase letters instead of the time zone is not the default and optional trailing in seconds even if their value is "00" should be included. It is also RECOMMENDED that all data items containing time durations conform to the "duration" production in Appendix A of RFC 3339, with the same additional restrictions. Also recommended that all data items included are in line with the duration of the "duration" RFC 3339 in Appendix A, and have the same additional restrictions.


#6th floor

There is only one correct answer to this and most systems get it wrong. There is only one correct answer, most systems come wrong. Number of milliseconds since epoch, aka a 64 bit integer. The number of milliseconds since the epoch, also known as 64-bit integer. Time Zone is a UI concern and has no business in the app layer or db layer. Time zone, there is no UI-related problems in the application layer or database layer affairs. Why does your db care what time zone something is, when you know it's going to store it as a 64 bit integer then do the transformation calculations. Why your database Why should we care what time zone when you know it will be 64-bit integer when storage and conversion calculations.

Strip out the extraneous bits and just treat dates as numbers up to the UI. Remove excess bits, only the date on which the numbers until the UI. You can use simple arithmetic operators to do queries and logic. You can use simple arithmetic operators to query and logic.

Original articles published 0 · won praise 73 · views 550 000 +

Guess you like

Origin blog.csdn.net/w36680130/article/details/105305836