解决方法
String[] ids=TimeZone.getAvailableIDs(); for(int i=0;i<ids.length;i++) { System.out.println("Availalbe ids.................."+ids[i]); TimeZone d= TimeZone.getTimeZone(ids[i]); System.out.println("time zone."+d.getDisplayName()); System.out.println("savings."+d.getDSTSavings()); System.out.println("offset."+d.getRawOffset()); ///////////////////////////////////////////////////// if (!ids[i].matches(".*/.*")) { continue; } String region = ids[i].replaceAll(".*/","").replaceAll("_"," "); int hours = Math.abs(d.getRawOffset()) / 3600000; int minutes = Math.abs(d.getRawOffset() / 60000) % 60; String sign = d.getRawOffset() >= 0 ? "+" : "-"; String timeZonePretty = String.format("(UTC %s %02d:%02d) %s",sign,hours,minutes,region); System.out.println(timeZonePretty); ////////////////////////////////////////////////////////////////// } ListView listitems=(ListView)findViewById(R.id.list); ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ids); listitems.setAdapter(adapter); }
TimeZone.http://developer.android.com/reference/java/util/TimeZone.html的文档
设置时区
以下是根据美国设置时区的示例代码
// First Create Object of Calendar Class Calendar calendar = Calendar.getInstance(); // Now Set the Date using DateFormat Class SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z"); // Finally Set the time zone using SimpleDateFormat Class's setTimeZone() Method sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));