我真的很困惑我用Calendar.getInstance(TimeZone.getTimeZone("UTC"))
方法調用得到的結果,它返回了IST時間。Calendar.getInstance(TimeZone.getTimeZone(「UTC」))沒有返回UTC時間
下面是我用
Calendar cal_Two = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
System.out.println(cal_Two.getTime());
的代碼,我得到的迴應是:
Sat Jan 25 15:44:18 IST 2014
所以我試圖改變的默認時區爲UTC,然後我檢查了,那麼它工作正常
Calendar cal_Two = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
System.out.println(cal_Two.getTime());
TimeZone tz = TimeZone.getDefault() ;
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Calendar cal_Three = Calendar.getInstance();
System.out.println(cal_Three.getTime());
TimeZone.setDefault(tz);
結果:
Sat Jan 25 16:09:11 IST 2014
Sat Jan 25 10:39:11 UTC 2014
我在這裏錯過了什麼嗎?
去掉了常規標籤,所有這一切都是純Java –