JAVA8 中 LocalDateTime的使用小栗子

时间:2022-09-05 15:30:15

 

        LocalDate givenDate = LocalDate.parse("2019-04-23",DateTimeFormatter.ofPattern("yyyy-MM-dd"));

        LocalDateTime startOfDay = givenDate.atTime(0,0,1);
        LocalDateTime endOfDay = givenDate.atTime(23,59,59);
        System.out.println(givenDate);
        System.out.println(givenDate.plusDays(1));

        System.out.println(startOfDay);
        System.out.println(endOfDay);

        Date fromDate = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
        Date toDate = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());

        System.out.println(fromDate);
        System.out.println(toDate);