mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
232c292dfc
commit
01ac41f08e
@ -8,6 +8,7 @@
|
|||||||
### 新特性
|
### 新特性
|
||||||
* 【socket】 对NioServer和NioClient改造(pr#992@Github)
|
* 【socket】 对NioServer和NioClient改造(pr#992@Github)
|
||||||
* 【core 】 StrUtil增加filter方法(pr#149@Gitee)
|
* 【core 】 StrUtil增加filter方法(pr#149@Gitee)
|
||||||
|
* 【core 】 DateUtil增加beginOfWeek重载
|
||||||
|
|
||||||
### Bug修复#
|
### Bug修复#
|
||||||
|
|
||||||
|
@ -1041,6 +1041,18 @@ public class DateUtil extends CalendarUtil {
|
|||||||
return new DateTime(beginOfWeek(calendar(date)));
|
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)));
|
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
|
@Test
|
||||||
public void beginAndWeedTest() {
|
public void beginOfWeekTest() {
|
||||||
String dateStr = "2017-03-01 22:33:23";
|
String dateStr = "2017-03-01 22:33:23";
|
||||||
DateTime date = DateUtil.parse(dateStr);
|
DateTime date = DateUtil.parse(dateStr);
|
||||||
Objects.requireNonNull(date).setFirstDayOfWeek(Week.MONDAY);
|
Objects.requireNonNull(date).setFirstDayOfWeek(Week.MONDAY);
|
||||||
@ -121,7 +121,7 @@ public class DateUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void beginAndWeedTest2() {
|
public void beginOfWeekTest2() {
|
||||||
String beginStr = "2020-03-11";
|
String beginStr = "2020-03-11";
|
||||||
DateTime date = DateUtil.parseDate(beginStr);
|
DateTime date = DateUtil.parseDate(beginStr);
|
||||||
Calendar calendar = date.toCalendar();
|
Calendar calendar = date.toCalendar();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user