Java8处理日期和时间

时间:2021-10-26 00:45:13
        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);