Java8处理日期和时间

时间:2022-11-11 22:08:37
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime time = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
        String localTime = df.format(time);
        System.out.println("LocalDateTime转成String类型的时间,并将时分秒设为0:"+localTime);


        LocalDateTime ldt = LocalDateTime.parse("2018-05-15 15:32:59",df);
        System.out.println("String类型的时间转成LocalDateTime:"+ldt);