I need to save the phone’s timezone in the format [+/-]hh:mm
I am using TimeZone class to deal with this, but the only format I can get is the following:
PST -05:00
GMT +02:00
I would rather not substring the result, is there any key or option flag I can set to only get the value and not the name of that timezone (GMT/CET/PST…)?
No, you don’t. Offset on its own is not enough, you need to store the whole time zone name/id. For example I live in Oslo where my current offset is +02:00 but in winter (due to dst) it is +01:00. The exact switch between standard and summer time depends on factors you don’t want to explore.
So instead of storing
+ 02:00(or should it be+ 01:00?) I store"Europe/Oslo"in my database. Now I can restore full configuration using:Want to know what is my time zone offset today?
However the same in December:
Enough to say: store time zone name or id and every time you want to display a date, check what is the current offset (today) rather than storing fixed value. You can use
TimeZone.getAvailableIDs()to enumerate all supported timezone IDs.