我正在尝试为用户获取时区。
为此,我有一个国家代码,这是一个有效的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);
}
但它总是返回服务器时区...
有什么想法吗?