JSON. stringify: the date and time are inaccurate when JSON is converted. json. stringifyjson
Call JSON. when stringify converts an object to a corresponding string, if it contains a time object, the time object will be converted to the national standard time (ISO) instead of the time of the current country region. The test code is as follows:
Copy codeThe Code is as follows:
<Script>
// Var o = new Date ();
// Console. log (o. toString () // China time zone, in the format of "Wed Jun 11 2014 10:51:42 GMT + 0800"
// Console. log (JSON. stringify (o); // output the International Standard Time (ISO), which is reduced by 8 hours, for example, "2014-06-11T02: 51: 42.624Z"
</Script>
JSON. stringify converts the Date object to the time zone of the current country, instead of the international standard time. You can rewrite the toJSON method of the prototype of the Date object and return the custom time format because of JSON. stringify calls the toJSON method of the Date object, for example:
Copy codeThe Code is as follows:
<Script>
Date. prototype. toJSON = function () {return this. toLocaleString ();}
Var o = new Date ();
Console. log (o. toString () // default format: "Wed Jun 11 2014 10:51:42 GMT + 0800"
Console. log (JSON. stringify (o); // output the custom local time: 10:57:27, January 1, June 11, 2014"
</Script>
How to Use JSONstringify () in js?
No problems.
Perform some tests
Alert ('json object created successfully'); // if you cannot see this, the error alert ('browser '+ (window. JSON? ''| 'Non') + JSON supported); alert (JSON. stringify (submit ));
In java, the list is converted to json format. After conversion, what should I do if the time format is incorrect?
The format may not be 2012-01-01 when you use JDBC for query.