Merge pull request #1036 from totalo/v5-dev

feat: add method isSameMonth
This commit is contained in:
Golden Looly 2020-08-24 17:19:19 +08:00 committed by GitHub
commit c38f9408be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
/**
* 比较两个日期是否为同一月
*
* @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>
*

View File

@ -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));
}
/**
* 计时常用于记录某段代码的执行时间单位纳秒
*