How to get the device timezone (Olson format0


#1

Hello,

When I make a POST request to my API server I pass a timestamp that relates to my data. I also pass the timezone that the user is currently in. How with ionic/cordova can I get the device timezone? I’ve a native iOS app that I built where getting the device timezone was quite simple however my ionic app is for android and I can’t see a way to get the timezone.

I do not want the timeOffset as that does not take into consideration daylight savings.

Thanks
-Nate


#2

Use this plugin:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-globalization/

Run this code:

navigator.globalization.getDatePattern(function(s){console.log(s);});

Output:

{pattern: "M/d/yy, h:mm a", timezone: "GMT", iana_timezone: "GMT", utc_offset: 0, dst_offset: 0}