我可以看到格林威治標準時間是'Z'常數,作爲GMT時間的指標。但是,當我解析GMT字符串時,它仍然打印當地時間。爲什麼這個日期沒有在GMT顯示?
代碼:
SimpleDateFormat outFormat = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String timeGMT = "2015-05-21T08:42:27.334Z";
try {
System.out.println("Time GMT>>>>>>"+outFormat.parse(timeGMT));
} catch (ParseException e) {
e.printStackTrace();
}
OUTPUT:
Thu May 21 08:42:27 IST 2015
預計:在您輸入
Thu May 21 08:42:27 GMT 2015
這個重複的問題解釋得很好: http://stackoverflow.com/questions/18122608/simpledateformat-parse-loses-timezone –
同意。但是'Z'常數呢。它應該被格式化爲'GMT'。那麼爲什麼我們需要設置時區。 –
請檢查此:http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date –