String类型的yyyy-MM-dd,转LocalDateTime,再转java.util.date

public static void main(String[] args) {

        ZoneId zone = ZoneId.systemDefault();
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime birthDate = LocalDateTime.parse("2022-03-11" + " 00:00:00", df);
        Instant instant = birthDate.atZone(zone).toInstant();
        Date date = Date.from(instant);
        System.out.println("birthDate: " + birthDate);
        System.out.println("instant: " + instant);
        System.out.println("date: " + date);
    }

结果:

birthDate: 2022-03-11T00:00
instant: 2022-03-10T16:00:00Z
date: Fri Mar 11 00:00:00 CST 2022

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