Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Android phones and timezones - TimezoneOffset returns old info

Hi!

This is not a question. Just to inform others working with timezones. This is only a problem on som Android phones and not on Iphones (IOS).

I you i.e. return from East Africa to Europe (CET) you can get this situation if you do not reboot your phone.

This code:
function GetDeviceTimezoneOffset() {
var d = new Date();
var n = d.getTimezoneOffset() * -1;
return "" + n;
}
ERROR: Returns 240 minutes instead of 60.

This code:
function checkDatePattern() {
navigator.globalization.getDatePattern(
function (date) { alert('Timezone: ' + date.timezone + '\n'); },
function () { alert('Error getting timezone\n'); },
{ formatLength: 'short', selector: 'date and time' }
);
}

Correct: Returns "Timezone: GMT+01:00"

When I get some spare time I will try to extract the offset in minutes from Cordova Globalization project instead as this is correct. (dst_offset property in Cordova module is not supported, and always returns zero.)

Best regards

Ole Henrik Oftedal
Timeflex Systemer AS
https://www.timeflex.no
http://www.timeflex.com
1 person likes
this idea
+1
Reply