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:

  1. let o result of calling toobject, giving value argument.
  2. let tv toprimitive(o, hint number).
  3. if tv number , not finite, return null.
  4. let toiso result of calling [[get]] internal method of o argument "toisostring". 5.if iscallable(toiso) false, throw typeerror exception.
  5. 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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -