java:如何获取时区缩写(从偏移量)? [英] java: how to get Timezone abbreviation (from offset)?
本文介绍了java:如何获取时区缩写(从偏移量)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下,我正在使用android。我发现不同的设备可能会有不同的结果。
My code like belows, I am using android. I found different devices may have different result.
使用不同的电话:我可以得到: EST或 GMT-05:00。
Using different phone: I can get : "EST" or "GMT-05:00".
但是,我只想获取缩写(就像 EST一样。)
However, I just want to get abbreviation(just like "EST").
我如何获取缩写(或更改偏移量)
How can I get the abbreviation (or change offset to abbreviation)?
String timezone =Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT);
推荐答案
如果其他人需要解决方案:我只是调整代码并获取所需的短名称,我需要向用户显示该短名称。
If anyone else need the solution : I just tweak the code and get desired short name, which i needed to display to user.
private static String getTimeZoneShortName() {
String tz = TimeZone.getDefault().getDisplayName();
String[] stz = tz.split(" ");
StringBuilder sName = new StringBuilder();
for (int i = 0; i < stz.length; i++) {
sName.append(stz[i].charAt(0));
}
return sName.toString();
}
这篇关于java:如何获取时区缩写(从偏移量)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文