Reputation: 8922
I have following Java Script (Json) date format
data.d1: "2015-03-26T16:00:00.0000000"
I execute the following
data.d1 = new Date(data.d1);
It gives the following outcome which is wrong to me.
Thu Mar 26 2015 20:00:00 GMT+0400 (Arabian Standard Time)
It should return
Thu Mar 26 2015 16:00:00 GMT+0400 (Arabian Standard Time)
Why there is 4 hour difference? How i can get the same time (without 4 hours addition to me default time)? Any hint please
p.s. i can get exact time back by using following line of code
data.d1.setHours(data.d1.getHours() - 4);
Is this the only way?
Upvotes: 3
Views: 116
Reputation: 17064
The 'T' in 2015-03-26T16:00:00.0000000
makes the Date
constructor take UTC timezone into consideration. For you it's +4 hours, for me, for instance, it's +2 hours.
If you want the neutral time, you need to remove the 'T' from the string and you'll get the desired result: 2015-03-26 16:00:00.0000000
See this question if you want a pure JS solution without altering your string, it will work I've tested it.
Upvotes: 1