Why Date.parse("2011-11-15")
considers current time zone in Web browser, and Date.parse("2011/11/15")
does not? Why the results are different?

- 334,321
- 69
- 703
- 674

- 5,614
- 1
- 31
- 23
-
Take a look at the answer in http://stackoverflow.com/questions/2587345/javascript-date-parse – Flexo Nov 17 '11 at 11:38
2 Answers
The first form is being considered as an ISO date in UTC, according to section 15.9.1.15 of ECMA-262. The second form is being considered in an implementation-specific way, as per section 15.9.4.2:
The
parse
function applies theToString
operator to its argument and interprets the resulting String as a date and time; it returns a Number, the UTC time value corresponding to the date and time. The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. The function first attempts to parse the format of the String according to the rules called out in Date Time String Format (15.9.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats
So I suspect "2011/11/15" is being converted to the local midnight of November 15th, whereas "2011-11-15" is being converted to UTC midnight of November 15th.

- 1,421,763
- 867
- 9,128
- 9,194
-
+1. As that last sentence quoted makes clear, moreover, it is not guaranteed that implementations will parse "2011-11-15" or "2011/11/15" differently, or the same. – Peter O. Nov 17 '11 at 11:38
-
@PeterO.: Indeed. The parsing of "2011-11-15" is guaranteed, but that's all. – Jon Skeet Nov 17 '11 at 11:42
-
the date/time string may be in ISO 8601 format. Starting with JavaScript 1.8.5 / Firefox 4, a subset of ISO 8601 is supported. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00 (date and time) can be passed and parsed. Timezones in ISO dates are not yet supported, so e.g. "2011-10-10T14:48:00+0200" (with timezone) does not give the intended result yet.

- 53,360
- 44
- 177
- 245
-
It's worth making it clear that that's the Date.parse documentation *for Firefox*. – Jon Skeet Nov 17 '11 at 11:42
-
@JonSkeet There is not a single specific website having java-script documentation,So i always take reference from MDC. if you know any good website then please refer me. Thanks :) – xkeshav Nov 17 '11 at 11:45
-
1See my answer, which refers to the ECMA-262 specification. But even if that didn't exist, it would be worth being explicit about which variant you *are* using. – Jon Skeet Nov 17 '11 at 11:49
-
I've seen MDC docs, and it doesn't answer the question - why the difference exists. ECMA is much more specific, thanks! – KIR Nov 17 '11 at 12:57