mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
!824 DateUtil 新增了获取本月最后一天,是否为本月最后一天
Merge pull request !824 from 特立独行的猪/v5-dev
This commit is contained in:
commit
8e5553a4aa
@ -2247,6 +2247,26 @@ public class DateUtil extends CalendarUtil {
|
|||||||
return startTime.before(realEndTime) && endTime.after(realStartTime);
|
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
|
// ------------------------------------------------------------------------ Private method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1094,4 +1094,12 @@ public class DateUtilTest {
|
|||||||
DateUtil.parse(sourceStr));
|
DateUtil.parse(sourceStr));
|
||||||
Assert.assertTrue(between);
|
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