Skip to content Skip to sidebar Skip to footer

Javascript Date - Preserve Timezone Offset

I have a ISO8601 date that contains a timezone offset (see below). When I create a Date object from this, the date object is converted into my timezone (currently GMT), and timezon

Solution 1:

Not with the built-in Date object, as they're only aware of Local (as defined by the user's browser and/or OS settings) and UTC. You can see this from the many cloned methods the class has (e.g., getHours / getUTCHours).

getTimezoneOffset is the only timezone info you really have, but it's local as well and will probably only give you +0 again (or +6 in my case):

var date = newDate("2012-01-17T12:55:00.000+01:00");
console.log(date.getTimezoneOffset() / 60.0);

You can try timezone-js (or one of its forks), but you'll need to know the Olson timezone name not just the GMT/UTC offset:

var date = newnew timezoneJS.Date('2012-01-17T12:55:00.000+01:00', 'Europe/Brussels');
alert(date.getTimezoneOffset() / 60.0); // +1

Post a Comment for "Javascript Date - Preserve Timezone Offset"