时间格式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

发布了39 篇原创文章 · 获赞 33 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/love1793912554/article/details/103985950