如何获得手机时区的缩写/国家code在android系统? [英] How to get the abbreviation / Country code of mobile timezone in android?

查看:946
本文介绍了如何获得手机时区的缩写/国家code在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得时区缩写像IST(印度标准时间),ET(东部时间)和所有。

How to get the Time Zone Abbreviation like IST (India Standard Time), ET (Eastern Time) and all.

我用下面的code得到android系统的时区信息,

I have used the below code to get the time zone information in android,

选项1:

String mobileTimeZone =  Calendar.getInstance().getTimeZone()
                    .getDisplayName(false, TimeZone.SHORT);

我选择了不同的时区和输出如下,

I chosen different time zone and the output as follows,

GMT + 13:00

GMT+13:00

GMT + 00:00

GMT+00:00

但是,当设置了一些它给了我正确的缩写,code作为输出,低于,时区

But when settings some of the time zone it gives me the proper abbreviation code as output which is below,

EST

和还我试过低于code这给时区的完整描述。

And also I tried the below code which gives the full description of timezone.

选项2:

String mobileTimeZone = Calendar.getInstance().getTimeZone().getID();

获取低于输出,只不过是区域名称:

Getting the below output which is nothing but zone name:

太平洋/中途岛

太平洋/火奴鲁鲁

美洲/蒙得维的亚

有没有身份证或拥有所有时区表对我来说,它映射的任何名单。

Is there any list of id or table having all the timezone for me to map it.

和还需要考虑日光节约。

And also need to consider the day light savings.

帮我从Android手机获得时区的缩写。

Help me to get the abbreviation of Time Zone from android mobile.

推荐答案

关于术语:

我们喜欢称之为美国/丹佛等字符串(格式为区/市)时区标识符,而不是名称。这些ID是在IANA-TZDB定义。 时区名称和缩写是一个完全不同的概念。这些数据通常有自己的CLDR-文件的起源(由的Uni code财团,例如的这里),并符合大多数人民期待他们的语言环境。这些名称是高度本地化。在一般情况下,没有国际标准,既不标识符也不为名称。后者的是刚刚下当地的风土人情。

We call strings like "America/Denver" etc. (in format region/city) timezone identifiers, not names. These ids are defined in IANA-TZDB. Timezone names and abbreviations are a totally different concept. Those data usually have their origins in CLDR-files (from Unicode consortium, for example here) and correspond to what most people expect IN THEIR LOCALES. These names are highly localized. In general, there is no international standard, neither for identifiers nor for names. Latter ones are just following local customs.

映射:

从时区标识符国家codeS,反之亦然映射可以在的 IANA-TZDB 。然后,您可以很快看到,有没有独特的映射如您所愿。例如:

A mapping from timezone identifiers to country codes and vice versa can be found in IANA-TZDB. You can then quickly see that there is no unique mapping as you expect. Examples:

欧洲/苏黎世在瑞士,德国(原文如此!)是有效的,并
  列支敦士登。

Europe/Zurich can be valid in Switzerland, Germany(sic!) and Liechtenstein.

或者平凡:

美国有多个时区(美国/纽约,美国/芝加哥
  等等。)

US has more than one timezone (America/New_York, America/Chicago, etc.)

您希望使用前pression获得独特的时区的缩写

Your hope to get unique timezone abbreviations using the expression

Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT);

是不现实的。 以获得您所描述TZ缩写的方法是正确的。但是,正如你已经在你的其他<一发现href=\"http://stackoverflow.com/questions/29351031/how-to-get-the-unique-timezone-display-name-in-all-the-android-devices\">SO-post结果不同从一个Android设备到另一个。主要的原因是,不同的设备(Dalvik的虚拟机)往往对时区的名称不同的数据(与OpenJDK的,Oracle的虚拟机,太)。

is not realistic. The method to get tz abbreviations you describe is correct. However, as you yourself have noticed in your other SO-post the results differ from one Android device to another. The main reason is that different devices (dalvik vms) often have different data for timezone names (and the OpenJDK-Oracle-VMs, too).

从时区名称和缩写的唯一映射到国家codeS通常是不可能的。反例:IST可以代表印度标准时间,或为以色列时区。或者:BST中的欧洲/伦敦时(在夏季),或在太平洋/布干维尔(全年)

A unique mapping from timezone names and abbreviations to country codes is usually not possible. Counter examples: "IST" can stand for "India Standard Time" or for Israel time zone. Or: "BST" is used in "Europe/London" (during summer time) or in "Pacific/Bougainville" (all the year).

有关夏令:

标识符不为夏令敏感。相关的数据可以是夏令与否,取决于相关的时间。时区名称和缩写通常(不总是)敏感,在美国比较如PST或PDT。

Identifiers are NOT sensitive for daylight saving. The related data can be daylight saving or not, dependent on the associated time. Timezone names and abbreviations are often (not always) sensitive, compare for example "PST" or "PDT" in US.

总结和建议:

不要使用时区名称或缩写比显示目的的任何其他。你不应该使用这些本地化的数据,任何结论或存储的目的。

Do not use timezone names or abbreviations for anything other than display purposes. You should not use these localized data for any conclusions or storage purposes.

这篇关于如何获得手机时区的缩写/国家code在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆