我正在尝试为用户获取 TimeZone。
为此,我有一个国家代码,它是一个有效的 ISO 国家代码。这些代码是 ISO-3166 定义的大写的两个字母代码。您可以在许多网站上找到这些代码的完整列表,例如: http: //www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
我认为答案是“不,因为这是多对多关系......像美国这样的国家可能有很多时区......”。那就是问题所在...
我尝试过类似的东西:
//CountryEnum contains ISO_3166 values (http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html)
//List all country to test timezone:
for (int i = 0; i < CountryEnum.values().length; i++) {
String isoCountryCode = CountryEnum.values()[i].name();// Get the iso country code
Locale locale = new Locale(isoCountryCode);// Build a country specific locale
Calendar calendar = Calendar.getInstance(locale);// Build a calendar with the specific locale
String timeZone = calendar.getTimeZone().getDisplayName();// Build a timeZone with the calendar
System.out.println("LOCALE : "+locale+" / COUNTRY: "+isoCountryCode+" / TIMEZONE: "+timeZone);
}
但它总是返回服务器 TimeZone ...
有任何想法吗 ?