nabeel riaz
nabeel riaz

Reputation: 11

Safari interpreting datetime string differently than chrome

Please see the attached screenshots. Why is this happening and what is the best solution?

The code for both is:

var d = new Date("2018-03-30T00:00:00");
document.getElementById("demo").innerHTML = d;

Chrome behaviour

Fri Mar 30 2018 00:00:00 GMT-0700 (PDT)

Safari behaviour

Thu Mar 29 2018 17:00:00 GMT-0700 (PDT)

Upvotes: 0

Views: 516

Answers (1)

Fenton
Fenton

Reputation: 251062

One of your browsers is assuming the input is in a different timezone to the other.

Try creating the date with timezone information:

var d = new Date("2018-03-30T00:00:00.000Z");

or,

var d = new Date("Fri, 30 Mar 2018 00:00:00 GMT");

Upvotes: 1

Related Questions