public static boolean isTodayOrLater(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.setTime(new Date());
    int currentYear = calendar.get(Calendar.YEAR);
    int currentMonth = calendar.get(Calendar.MONTH);
    int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
    if (year > currentYear || (year == currentYear && month > currentMonth)) {
        return false;
    }
    if (year == currentYear && month == currentMonth) {
        if (day > currentDay) {
            return false;
        }
        if (day == currentDay) {
            return true;
        }
        calendar.set(Calendar.MONTH, month + 1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        if (currentDay == calendar.get(Calendar.DAY_OF_MONTH)) {
            return true;
        }
    }
    return false;
}
用Java实现一个工具方法根据传入的Date判断是否是当天当天返回true传入的日期大于本月最后一天的且今天是最后一天返回true其他返回false

原文地址: https://www.cveoy.top/t/topic/bJCG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录