JDK8 时间api-当天的开始和截至时间

public static Date getTodayStart() {
        LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        Instant instant = todayStart.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    public static Date getTodayEnd() {
        LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        Instant instant = todayStart.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    public static Date getSomeDayStart(int plusDays) {
        LocalDateTime todayStart = LocalDateTime.of(LocalDate.now().plusDays(plusDays), LocalTime.MIN);
        Instant instant = todayStart.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    public static Date getSomeDayEnd(int plusDay) {
        LocalDateTime todayStart = LocalDateTime.of(LocalDate.now().plusDays(plusDay), LocalTime.MAX);
        Instant instant = todayStart.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

 

posted on 2021-12-24 10:21  MaXianZhe  阅读(117)  评论(0编辑  收藏  举报

导航