使用 Timezone.getTimeZone("Antarctica/Casey"),某些时区返回无效输出。例如,
SimpleDateFormat outputFormat = new SimpleDateFormat( "MM/dd/yyyy hh:mm aa zzz" );
outputFormat.setTimeZone( TimeZone.getTimeZone( "Antarctica/Casey" ) );
System.out.println(outputFormat.format( new Date() ));
它应该返回“MM/dd/yyyy hh:mm aa CAST”,但它返回“MM/dd/yyyy hh:mm aa WST”。
像这样还有其他一些问题,
- 澳大利亚/阿德莱德 - ACST/ACDT
- 澳大利亚/尤克拉 - ACWST/ACWDT
- 澳大利亚/悉尼 - AEST/AEDT
- 南极洲/莫森 - AHMT
- 澳大利亚/珀斯 - AWST/AWDT
- 太平洋/阿皮亚 - SST。
最佳答案
如果你勾选the IANA Time Zone Database ,您会看到 Casey 当前处于 WST 时区,并且自 2012 年 2 月以来一直处于该时区。
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Antarctica/Casey 0 - zzz 1969
8:00 - WST 2009 Oct 18 2:00
# Western (Aus) Standard Time
11:00 - CAST 2010 Mar 5 2:00
# Casey Time
8:00 - WST 2011 Oct 28 2:00
11:00 - CAST 2012 Feb 21 17:00u
8:00 - WST
这里是对更改的更详细引用:http://www.timeanddate.com/news/time/antarctica-2012.html .
但是 WST 仅在打印时使用:在内部正确处理从 GMT+8 到 GMT+11 的变化。参见示例:
public static void main(String[] args) {
SimpleDateFormat outputFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm aa Z");
TimeZone tz = TimeZone.getTimeZone("Antarctica/Casey");
outputFormat.setTimeZone(tz);
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
//May 2014 = GMT + 8
System.out.println(outputFormat.format(c.getTime()));
//january 2012 = GMT + 11
c.set(Calendar.YEAR, 2012);
c.set(Calendar.MONTH, 0);
System.out.println(outputFormat.format(c.getTime()));
}
至于其他的区别,大概就是夏令时和冬令时的区别吧。
关于Java 时区问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23477891/