If i create Date object with new Date('2015-03-25') , I'm getting object as Tue Mar 24 2015 16:00:00 GMT-0800 (AKDT). Is it expected ?
Asked
Active
Viewed 113 times
1
-
Depends on the edition of the language the engine has implemented. When parsing `YYYY-MM-DD`... With ES5, if a timezone isn't provided, UTC is assumed. With ES6, that changed to assume the user's timezone. – Related: [Why does Date.parse give incorrect results?](http://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – Jonathan Lonowski Apr 25 '16 at 05:45
-
1Also, [Why isn't “2016-02-16” equal to “2016-02-16 00:00”?](http://stackoverflow.com/questions/35448343/why-isnt-2016-02-16-equal-to-2016-02-16-0000) – Jonathan Lonowski Apr 25 '16 at 05:50
-
Thanks @JonathanLonowski . – Pranav Raj S Apr 25 '16 at 05:53
-
@JonathanLonowski—Nope, ECMAScript 2015 assumes UTC too (see this [*TC39 discussion*](https://github.com/tc39/ecma262/issues/87)). But regardless, strings should never be parsed using the Date constructor or Date.parse. Do it manually (2 line function will do, or library if you must). – RobG Apr 25 '16 at 10:51
-
@RobG Yeah, looks like ES 2016 (ES7) plans to change it back to UTC for date-only strings, but that's not yet released and can still change. For now, the published standard uses local time if absent, even if engines are instead adhering to the next draft. – Jonathan Lonowski Apr 25 '16 at 15:56
-
@JonathanLonowski—date–only formats should have been treated as UTC since ES 5.1 (i.e. there is no "changing back") per the [*TC39 discussion*](https://github.com/tc39/ecma262/issues/87) linked to earlier. The current versions of all browsers treat them as UTC (as far as I know), there were some recent versions (less than 12 months old) that treated them as local. The bottom line remains: don't use Date.parse or the Date constructor to parse strings. – RobG Apr 25 '16 at 23:08
-
@RobG So, "revert" and "change back" aren't at all alike? :) I read the discussion and I understand current implementations follow ES5.1 or ES7 for date-only ISO strings. Firefox, at least, did follow ES6 for a while. Still, I was referring to the specification itself – how it's written down, not coded – which is changing back partially to UTC from ES6 to ES7. And, I agree with your bottom line. – Jonathan Lonowski Apr 25 '16 at 23:15
-
@JonathanLonowski—you might think the literal text means that (I happen to agree with you) but the technical committee does not. :-( – RobG Apr 25 '16 at 23:24
1 Answers
1
Is it expected?
Unfortunately Ecma TC39 decided that date only forms of ISO 8601 strings should be treated as UTC and not local (per ISO 8601).
You might care to read Matt Johnson's blog on the issue.
The only reliable way to parse date strings is to do it manually. A library can help, but is usually not necessary.

RobG
- 142,382
- 31
- 172
- 209