mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
Merge pull request #1036 from totalo/v5-dev
feat: add method isSameMonth
This commit is contained in:
commit
c38f9408be
@ -289,6 +289,21 @@ public class CalendarUtil {
|
||||
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>
|
||||
*
|
||||
|
@ -1495,6 +1495,22 @@ public class DateUtil extends CalendarUtil {
|
||||
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…
Reference in New Issue
Block a user