How to assume local time zone when parsing ISO 8601 date string?

According to MDN:

Differences in assumed time zone

Given a date string of “March 7, 2014”, parse() assumes a local time
zone, but given an ISO format such as “2014-03-07” it will assume a
time zone of UTC. Therefore Date objects produced using those strings
will represent different moments in time unless the system is set with
a local time zone of UTC. This means that two date strings that appear
equivalent may result in two different values depending on the format
of the string that is being converted (this behavior is changed in
ECMAScript ed 6 so that both will be treated as local).

I have done like this and am now getting the exact time which is inside the ISO date string instead of the local time

 var startTimeISOString = "2013-03-10T02:00:00Z";

 var startTime = new Date(startTimeISOString );
 startTime =   new Date( startTime.getTime() + ( startTime.getTimezoneOffset() * 60000 ) );

This will give the same date time inside iso date string , the output here is

o/p

Date {Sun Mar 10 2013 02:00:00 GMT+0530 (India Standard Time)}

Leave a Comment