javascript - Differring behaviour of Date.parse? -
alert(date.parse('mar 1 1990'));
in jsfiddle, returns datetime integer, expected. on machine, returns... timestamp string?
thu mar 01 1990 00:00:00 gmt-0500 (est)
vs 636267600000
ecmascript language specification
15.9.4.2 date.parse (string)
the parse function applies tostring operator argument , interprets resulting string date , time; it returns number, utc time value corresponding date , time. string may interpreted local time, utc time, or time in other time zone, depending on contents of string. function first attempts parse format of string according rules called out in date time string format (15.9.1.15). if string not conform format function may fall implementation-specific heuristics or implementation-specific date formats. unrecognizable strings or dates containing illegal element values in format string shall cause date.parse return nan.
what did wrong 2 tests not same:
alert(date.parse('mar 1 1990'));
returns number (always)
alert(new date('mar 1 1990'));
returns string mentioned
(because tostring method called on date object)
Comments
Post a Comment