0

Okay, this is bizarre. I've got this Date object:

2015-10-13T00:00:00.000Z

I call this function:

date.setHours(12, 0, 0, 0);

...and I get get back this:

2015-10-12T19:00:00.000Z

Why in the world would that be happening?

David Stein
  • 866
  • 7
  • 21
  • 6
    `.setHours()` uses your (or the user's) local time zone while the `Z` in the output represents [UTC](http://en.wikipedia.org/wiki/Coordinated_Universal_Time). Try [`.setUTCHours()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours). – Jonathan Lonowski May 23 '15 at 21:51
  • See [JavaScript setUTCHours returns wrong day](http://stackoverflow.com/q/23281932/1529630) and [Javascript date object always one day off?](http://stackoverflow.com/q/7556591/1529630) – Oriol May 23 '15 at 22:50

1 Answers1

2

I ran into this kind of problem once, though this helped me.

var d = new Date();
d.setUTCHours(15);

result:

Sat May 23 2015 20:03:43 GMT+0500 (PKT)

Shayan Ahmad
  • 952
  • 8
  • 17