時間格式2020-01-13T16:00:00.000Z中的T和Z分別表示什麼,如何處理

T表示分隔符,Z表示的是UTC。
UTC:世界標準時間,在標準時間上加上8小時,即東八區時間,也就是北京時間。

舉例   

北京時間:2020-01-14 00:00:00對應的國際標準時間格式爲:2020-01-13T16:00:00.000Z

 

String dateTime = "2020-01-13T16:00:00.000Z";
dateTime = dateTime.replace("Z", " UTC");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    Date time = format.parse(dateTime);
    String result = defaultFormat.format(time);
    System.out.println(result);
} catch (Exception e) {
    e.printStackTrace();
}

// 輸出結果:2020-01-14 00:00:00

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章