javascript - Different date values -
why happen when convert date json?
var = new date(); // returns wed apr 29 2015 18:15:33 gmt+0100 (gmt daylight time) var nowjson = now.tojson(); // returns "2015-04-29t17:15:33.863z"
notice hour of each variable different...
when new date()
printed console, operating system defines locale , format printing. wed apr 29 2015 18:15:33 gmt+0100 (gmt daylight time)
browser has deemed default.
when print .tojson
, happens:
http://es5.github.io/#x15.9.5.44
this function provides string representation of date object use json.stringify (15.12.3).
when tojson method called argument key, following steps taken:
- let o result of calling toobject, giving value argument.
- let tv toprimitive(o, hint number).
- if tv number , not finite, return null.
- let toiso result of calling [[get]] internal method of o argument "toisostring". 5.if iscallable(toiso) false, throw typeerror exception.
- return result of calling [[call]] internal method of toiso o value , empty argument list.
http://es5.github.io/#x15.9.5.43
15.9.5.43 date.prototype.toisostring ( )
this function returns string value represent instance in time represented date object. format of string date time string format defined in 15.9.1.15. fields present in string. time zone utc, denoted suffix z. if time value of object not finite number rangeerror exception thrown.
http://es5.github.io/#x15.9.1.15
15.9.1.15 date time string format
ecmascript defines string interchange format date-times based upon simplification of iso 8601 extended format. format follows: yyyy-mm-ddthh:mm:ss.sssz
the reason dates can serialized string , brought object without loss of data.
Comments
Post a Comment