编程语言
首页 > 编程语言> > java 判断日期是否小于本月

java 判断日期是否小于本月

作者:互联网

/**
 * 判断日期是否小于本月
 * @param date
 * @return
 */
private boolean isLessThanThisMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    //设置为1号,当前日期既为本月第一天
    cal.set(Calendar.DAY_OF_MONTH, 1);
    //将小时至0
    cal.set(Calendar.HOUR_OF_DAY, 0);
    //将分钟至0
    cal.set(Calendar.MINUTE, 0);
    //将秒至0
    cal.set(Calendar.SECOND,0);
    //将毫秒至0
    cal.set(Calendar.MILLISECOND, 0);
    return date.before(cal.getTime());
}

 

标签:小于,set,java,日期,cal,date,return,Calendar,DAY
来源: https://www.cnblogs.com/BobXie85/p/15853167.html