我想构建一个时区列表以显示给用户选择。显示名称必须类似于:
( GMT 5:30 ) India Standard Time(Asia/Calcutta)
我正在使用所有时区TimeZone.getAvailableIDs()
并构建列表。我写的代码是:
String[] timeZones = TimeZone.getAvailableIDs();
List<String> tzList = new ArrayList<String>();
for (String timeZone : timeZones)
{
TimeZone tz = TimeZone.getTimeZone(timeZone);
StringBuilder timeZoneStr = new StringBuilder();
timeZoneStr.append("( GMT ").append(tz.getRawOffset() / (60 * 60 * 1000)).append(" ) ").append(tz.getDisplayName()).append("(").append(timeZone).append(")");
tzList.add(timeZoneStr.toString());
System.out.println(timeZoneStr.toString());
}
输出的片段如下:
( GMT 5 ) Maldives Time(Indian/Maldives)
( GMT 5 ) Pakistan Time(PLT)
( GMT 5 ) India Standard Time(Asia/Calcutta)
( GMT 5 ) India Standard Time(Asia/Kolkata)
( GMT 5 ) India Standard Time(IST)
但我需要得到的输出是:
( GMT 5:0 ) Maldives Time(Indian/Maldives)
( GMT 5:0 ) Pakistan Time(PLT)
( GMT 5:30 ) India Standard Time(Asia/Calcutta)
( GMT 5:30 ) India Standard Time(Asia/Kolkata)
( GMT 5:30 ) India Standard Time(IST)
我应该怎么做才能得到 5:30?