mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
Merge branch 'v5-dev' of gitee.com:dromara/hutool into v5-dev
This commit is contained in:
commit
c4133dd981
@ -2247,6 +2247,26 @@ public class DateUtil extends CalendarUtil {
|
||||
return startTime.before(realEndTime) && endTime.after(realStartTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为本月最后一天
|
||||
* @param dateTime {@link DateTime}
|
||||
* @return 是否为本月最后一天
|
||||
* @since 5.8.8
|
||||
*/
|
||||
public static boolean isLastDayOfMonth(DateTime dateTime){
|
||||
return dateTime.dayOfMonth()==getLastDayOfMonth(dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得本月的最后一天
|
||||
* @param dateTime {@link DateTime}
|
||||
* @return 天
|
||||
* @since 5.8.8
|
||||
*/
|
||||
public static int getLastDayOfMonth(DateTime dateTime){
|
||||
return Month.getLastDay(dateTime.month(),dateTime.isLeapYear());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------ Private method start
|
||||
|
||||
/**
|
||||
|
@ -1094,4 +1094,12 @@ public class DateUtilTest {
|
||||
DateUtil.parse(sourceStr));
|
||||
Assert.assertTrue(between);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLastDayTest(){
|
||||
DateTime dateTime = DateUtil.parse("2022-09-30");
|
||||
int dayOfMonth = DateUtil.getLastDayOfMonth(dateTime);
|
||||
Assert.assertEquals(dayOfMonth,dateTime.dayOfMonth());
|
||||
Assert.assertTrue("not is last day of this month !!",DateUtil.isLastDayOfMonth(dateTime));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user