feat: add method isSameMonth

This commit is contained in:
tangguocheng1 2020-08-24 13:28:43 +08:00
parent b46d99a15a
commit a248bbc4d0
2 changed files with 31 additions and 0 deletions

View File

@ -289,6 +289,21 @@ public class CalendarUtil {
cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA); cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA);
} }
/**
* 比较两个日期是否为同一月
*
* @param cal1 日期1
* @param cal2 日期2
* @return 是否为同一月
*/
public static boolean isSameMonth(Calendar cal1, Calendar cal2) {
if (cal1 == null || cal2 == null) {
throw new IllegalArgumentException("The date must not be null");
}
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && //
cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
}
/** /**
* <p>检查两个Calendar时间戳是否相同</p> * <p>检查两个Calendar时间戳是否相同</p>
* *

View File

@ -1495,6 +1495,22 @@ public class DateUtil extends CalendarUtil {
return CalendarUtil.isSameDay(calendar(date1), calendar(date2)); return CalendarUtil.isSameDay(calendar(date1), calendar(date2));
} }
/**
* 比较两个日期是否为同一月
*
* @param date1 日期1
* @param date2 日期2
* @return 是否为同一月
* @since 5.4.11
*/
public static boolean isSameMonth(final Date date1, final Date date2) {
if (date1 == null || date2 == null) {
throw new IllegalArgumentException("The date must not be null");
}
return CalendarUtil.isSameMonth(calendar(date1), calendar(date2));
}
/** /**
* 计时常用于记录某段代码的执行时间单位纳秒 * 计时常用于记录某段代码的执行时间单位纳秒
* *