判断是否今天,今年

public static boolean isToday(long ts) {
        LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0, 0));
        LocalDateTime tommorrow = today.plusDays(1);
        long todaySecond = today.atZone(ZoneId.systemDefault()).toEpochSecond();
        long tomorrowSeconds = tommorrow.atZone(ZoneId.systemDefault()).toEpochSecond();
        return ts >= todaySecond && ts < tomorrowSeconds;
    }

    public static boolean isThisYear(long ts) {
        Instant instant = Instant.ofEpochSecond(ts);
        LocalDate date = LocalDate.ofInstant(instant, ZoneId.systemDefault());
        return date.getYear() == LocalDate.now().getYear();
    }

 

posted @ 2019-05-20 12:24  java渣渣  阅读(1560)  评论(0编辑  收藏  举报