问题
I have used the below code to get the android mobile timezone display name.
String mobileTimeZone = Calendar.getInstance().getTimeZone()
.getDisplayName(false, TimeZone.SHORT);
But running the same code in two different devices returns two different values as follows,
In Sony xperia Z1, it returns IST.
In Samsung Galaxy S3, it returns GMT+05.30.
How to get the unique value like IST or ET in all the devices.
Please help me on to solve this issue.
回答1:
I see the same GMT+5:30 on my Huawei Phone (android 4.4.2).
Please note that the use of two or three character time zone identifiers is deprecated. This is because they are in fact NOT unique. The same value can actually represent different time zones (e.g. CST can mean Central Standard Time and also China Standard Time - see javadoc for Timezone for more information).
If you need a unique identifier for a Timezone, use the getID() method on the Timezone class. This will return a value like "Asia/Kolkata". This same value can be used to construct a TimeZone using TimeZone.getTimeZone("Asia/Kolkata").
来源:https://stackoverflow.com/questions/29351031/how-to-get-the-unique-timezone-display-name-in-all-the-android-devices