Java时间格式UTC转换成CST

    /**
     * description UTC时间格式转换成CST
     *
     * @author yanzy
     * @version 1.0
     * @date 2022/6/24 15:18
     */
    public static String UTCtoCST(String utc) {
        ZonedDateTime zdt = ZonedDateTime.parse(utc);
        LocalDateTime localDateTime = zdt.toLocalDateTime();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return formatter.format(localDateTime.plusHours(8));
    }
    public static void main(String[] args) {
        System.out.println(UTCtoCST("2022-06-24T12:20:13+08:00"));
    }

结果:2022-06-24 20:20:13

你可能感兴趣的:(Java,java,开发语言)