mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -1041,6 +1041,18 @@ public class DateUtil extends CalendarUtil {
|
||||
return new DateTime(beginOfWeek(calendar(date)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某周的开始时间
|
||||
*
|
||||
* @param date 日期
|
||||
* @param isMondayAsFirstDay 是否周一做为一周的第一天(false表示周日做为第一天)
|
||||
* @return {@link DateTime}
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public static DateTime beginOfWeek(Date date, boolean isMondayAsFirstDay) {
|
||||
return new DateTime(beginOfWeek(calendar(date), isMondayAsFirstDay));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某周的结束时间,周日定为一周的结束
|
||||
*
|
||||
@@ -1051,6 +1063,18 @@ public class DateUtil extends CalendarUtil {
|
||||
return new DateTime(endOfWeek(calendar(date)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某周的结束时间
|
||||
*
|
||||
* @param date 日期
|
||||
* @param isSundayAsLastDay 是否周日做为一周的最后一天(false表示周六做为最后一天)
|
||||
* @return {@link DateTime}
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public static DateTime endOfWeek(Date date, boolean isSundayAsLastDay) {
|
||||
return new DateTime(endOfWeek(calendar(date), isSundayAsLastDay));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某月的开始时间
|
||||
*
|
||||
|
@@ -99,7 +99,7 @@ public class DateUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beginAndWeedTest() {
|
||||
public void beginOfWeekTest() {
|
||||
String dateStr = "2017-03-01 22:33:23";
|
||||
DateTime date = DateUtil.parse(dateStr);
|
||||
Objects.requireNonNull(date).setFirstDayOfWeek(Week.MONDAY);
|
||||
@@ -121,7 +121,7 @@ public class DateUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beginAndWeedTest2() {
|
||||
public void beginOfWeekTest2() {
|
||||
String beginStr = "2020-03-11";
|
||||
DateTime date = DateUtil.parseDate(beginStr);
|
||||
Calendar calendar = date.toCalendar();
|
||||
|
Reference in New Issue
Block a user