How to get the unique TimeZone Display name in all the android devices?

ε祈祈猫儿з 提交于 2020-01-17 04:19:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!