mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
feat: add method isSameMonth
This commit is contained in:
parent
b46d99a15a
commit
a248bbc4d0
@ -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>
|
||||||
*
|
*
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计时,常用于记录某段代码的执行时间,单位:纳秒
|
* 计时,常用于记录某段代码的执行时间,单位:纳秒
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user