简体   繁体   English

如何在所有android设备中获取唯一的时区显示名称?

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

I have used the below code to get the android mobile timezone display name. 我已经使用下面的代码来获取android移动时区的显示名称。

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 . 在Sony xperia Z1中,它返回IST

In Samsung Galaxy S3, it returns GMT+05.30 . 在Samsung Galaxy S3中,它返回GMT + 05.30

How to get the unique value like IST or ET in all the devices. 如何在所有设备中获得像IST或ET这样的唯一值。

Please help me on to solve this issue. 请帮我解决这个问题。

I see the same GMT+5:30 on my Huawei Phone (android 4.4.2). 我在华为手机(android 4.4.2)上看到相同的GMT + 5:30。

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 (eg CST can mean Central Standard Time and also China Standard Time - see javadoc for Timezone for more information). 相同的值实际上可以表示不同的时区(例如,CST可以表示中央标准时间,也可以表示中国标准时间-有关更多信息,请参见javadoc中的时区)。

If you need a unique identifier for a Timezone, use the getID() method on the Timezone class. 如果您需要时区的唯一标识符,请在时区类上使用getID()方法。 This will return a value like "Asia/Kolkata". 这将返回类似“亚洲/加尔各答”的值。 This same value can be used to construct a TimeZone using TimeZone.getTimeZone("Asia/Kolkata"). 可以使用相同的值通过TimeZone.getTimeZone(“ Asia / Kolkata”)构造TimeZone。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM