Java判断传入的月是不是上个月的(支持跨年)

java 文章 2022-12-01 14:06 369 0 全屏看文

AI助手支持GPT4.0

private boolean isLastMonth(Date date) {
	return isLastMonth(new Date(), date);
}

public  boolean isLastMonth(Date date,Date date2) {
	Calendar nextMonth = Calendar.getInstance();
	nextMonth.setTime(date);
	nextMonth.add(Calendar.MONTH, -1);
	
	Calendar c2 = Calendar.getInstance();
	c2.setTime(date2);
	
	if(c2.get(Calendar.YEAR) == nextMonth.get(Calendar.YEAR) && c2.get(Calendar.MONTH) == nextMonth.get(Calendar.MONTH)) {
		return true;
	}
	return false;
}


-EOF-

AI助手支持GPT4.0