mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
新增了获取本月最后一天,是否为本月最后一天
This commit is contained in:
parent
42a427193b
commit
ee12875bf3
@ -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