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