java: how to get Timezone abbreviation (from offset)?

只愿长相守 提交于 2019-12-11 02:07:12

问题


My code like belows, I am using android. I found different devices may have different result.

Using different phone: I can get : "EST" or "GMT-05:00".

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);

回答1:


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();
}


来源:https://stackoverflow.com/questions/39984302/java-how-to-get-timezone-abbreviation-from-offset

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