Pranav Raj S
Pranav Raj S

Reputation: 86

new Date() with ISO 8061 date creates date according to timezone

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 ?

Upvotes: 1

Views: 136

Answers (1)

RobG
RobG

Reputation: 147363

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.

Upvotes: 1

Related Questions