The outmoded TimeZone.getDefault()
and its modern equivalent, ZoneId.systemDefault()
both return the time zone setting of the JVM. Unless something special has been done to obtain something else, this will be the same as the device’ time zone setting when the JVM is launched. It may later be changed by your program or by other programs running in the same JVM. On the other hand, if you change the device setting, this will not affect the JVM (until a new JVM is launched).
Most likely your devices have different time zone settings. I would consider the setting Asia/Singapore more correct, even though for practical everyday purposes UTC+08:00 is equivalent. The latter is not a true time zone, and when it comes to historical dates it will not always agree with Singapore time. Asia/Singapore time is also known as Singapore Time, SGT, Singapore Standard Time or SST. The last abbreviation is also shared with Samoa Standard Time, which is a completely different time zone (so avoid those three and four letter abbreviations).
A time zone, like Asia/Singapore, is an area (zone) sharing the same time, like the Republic of Singapore, and encompasses not only the current offset from UTC, but also historic and known future changes of offset. An offset from UTC or GMT, like +08:00, on the other hand, hasn’t got any inherent place or time it’s valid. Its validity in a certain area at a certain time follows only from the time zone. So using an offset as the time zone setting of a device is questionable at best. The old class TimeZone
can be used for representing either a time zone or an offset, which may blur the distinction. In java.time
, the distinction has been made between ZoneId
(a time zone with a name, typically and recommended in the region/city format) and a ZoneOffset
. For pragmatic/practical reasons, a ZoneOffset
can also be used where a ZoneId
is required (made possible through inheritance).
java.time
As an aside consider throwing away the long outmoded TimeZone
and friends and using java.time
, the modern Java date and time API, instead. It is so much nicer to work with. The modern class you need is ZoneId
. It too has a fine getDisplayName
method.
- In Java 8 and later and on newer Android devices
java.time
comes built-in.
- In Java 6 and 7 get the ThreeTen Backport, the backport of the new classes (ThreeTen for JSR 310; see the links at the bottom).
- On older Android use the Android edition of ThreeTen Backport. It’s called ThreeTenABP. And make sure you import the date and time classes from
org.threeten.bp
with subpackages.
Links