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:
With Java 8, you can achieve this by following code.
TimeZone tz = TimeZone.getDefault();
String offsetId = tz.toZoneId().getRules().getStandardOffset(Instant.now()).getId();
and the offsetId will be something like +01:00
Please notice the function getStandardOffset need a Instant as parameter. It is the specific time point, at which you want to check the offset of given timezone, as timezone's offset may varies during time. For the reason of some areas have Daylight Saving Time.
I think it is the reason why @Tomasz Nurkiewicz recommand not to store offset in signed hour format directly, but to check the offset each time you need it.