java-ZonedDateTime将正常时间戳转换为yyyy-MM-dd'T'HH:mm:ssz格式的时间戳

DateTimeFormatter formatter0 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.of("Asia/Shanghai"));

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssz");

ZonedDateTime zoneTime = ZonedDateTime.parse("2018-08-07 08:00:01", formatter0);

System.out.println(zoneTime.withFixedOffsetZone().format(formatter));

输出结果:2018-08-07T08:00:01+08:00

此处有ZonedDateTime类的详细API:

http://www.cnblogs.com/lshan/p/9221296.html

原文地址:https://www.cnblogs.com/yizw/p/10117858.html