A have a date on a string on the format yyyy-MM-ddTHH:mm:ss
I need to create a javascript Date object, so I do
var d = new Date('2017-07-01T00:38:00')
and the created object is
Sat Jul 01 2017 00:38:00 GMT+0100 (GMT Daylight Time)
This is what I expect and what is happening on Chrome (v 59.0.3071.115 ) on my Desktop.
When I run the same code on my android phone, with Chrome version 51.0.2704.81 the result is
Sat Jul 01 2017 01:38:00 GMT+0100 (GMT Daylight Time)
As you can see the hour is different due to my local timezone.
Is any of the above behaviors an expected one? Is it a matter of Chrome version? On my search I understood that the Date constructor with a string date produces unexpected results but can I rely on constant behavior independently of the browser?
EDIT
It's not a duplicate because on Firefox I have the same result that Chrome v59, the datetime is interpreted as local date and not UTC (that's what I want).
EDIT 2
On the "alleged" duplicated question the 'asker's' objective is that the new Date()
treats the inserted date as UTC and make the necessary conversion to the users local time.
What I want is that the new Date()
process the inserted date as local date without making any conversions. This is the behavior I'm getting on recent browsers (Chrome, Firefox) but no on old version of Chrome (in Android, v51).
So, if the users is on a timezone with +01:00 offset, if I make new Date('2017-07-01T00:38:00')
the result should be Sat Jul 01 2017 00:38:00 GMT+0100
EDIT 3
Just checked that if I use the constructor new Date(2017,06,01,0,38,0)
the date is interpreted as localdate (it shows Sat Jul 01 2017 00:38:00 GMT+0100 (GMT Daylight Time)
on both versions of chrome... Is there any documentation that I can rely to be sure that will always interpreted as local date?