I want to parse date without timezone in JavaScript. I have tried:
new Date(Date.parse("2005-07-08T00:00:00+0000"));
Returns Fri Jul 08 2005 02:00:00 GMT+0200 (Central European Daylight Time)
new Date(Date.parse("2005-07-08 00:00:00 GMT+0000"));
Returns same result
new Date(Date.parse("2005-07-08 00:00:00 GMT-0000"));
Returns same result
I want to parse time:
Without time zone.
Without calling constructor Date.UTC or new Date(year, month, day).
Just simple passing string into Date constructor (without prototype approaches).
I have to product Date
object, not String
.
I have the same issue. I get a date as a String, for example: '2016-08-25T00:00:00', but I need to have Date object with correct time. To convert String into object, I use getTimezoneOffset:
var date = new Date('2016-08-25T00:00:00')
var userTimezoneOffset = date.getTimezoneOffset() * 60000;
new Date(date.getTime() - userTimezoneOffset);
getTimezoneOffset()
will return ether negative or positive value. This must be subtracted to work in every location in world.