Skip to content

Commit

Permalink
LocalDateTimeUtil增加beginOfDay和endOfDay重载
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed May 23, 2024
1 parent 1fc4148 commit 2f1583a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* 【core 】 ListUtil.setOrPadding增加重载,可选限制index大小(issue#3586@Github)
* 【http 】 getFileNameFromDisposition更加规范,从多个头的值中获取,且`filename*`优先级更高(pr#3590@Gitee)
* 【core 】 CsvWriter增加重载writeBeans方法,支持可选bean字段(pr#1222@Gitee)
* 【core 】 LocalDateTimeUtil增加beginOfDay和endOfDay重载(issue#3594@Github)

### 🐞Bug修复
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@ public static LocalDateTime beginOfDay(LocalDateTime time) {
return time.with(LocalTime.MIN);
}

/**
* 修改为一天的开始时间,例如:2020-02-02 00:00:00,000
*
* @param date 日期时间
* @return 一天的开始时间
* @since 5.8.28
*/
public static LocalDateTime beginOfDay(LocalDate date) {
return LocalDateTime.of(date, LocalTime.MIN);
}

/**
* 修改为一天的结束时间,例如:2020-02-02 23:59:59,999
*
Expand All @@ -488,6 +499,17 @@ public static LocalDateTime endOfDay(LocalDateTime time) {
return endOfDay(time, false);
}

/**
* 修改为一天的结束时间,例如:2020-02-02 23:59:59,999
*
* @param date 日期时间
* @return 一天的结束时间
* @since 5.8.28
*/
public static LocalDateTime endOfDay(LocalDate date) {
return endOfDay(date, false);
}

/**
* 修改为一天的结束时间,例如:
* <ul>
Expand All @@ -507,6 +529,25 @@ public static LocalDateTime endOfDay(LocalDateTime time, boolean truncateMillise
return time.with(LocalTime.MAX);
}

/**
* 修改为一天的结束时间,例如:
* <ul>
* <li>毫秒不归零:2020-02-02 23:59:59,999</li>
* <li>毫秒归零:2020-02-02 23:59:59,000</li>
* </ul>
*
* @param date 日期时间
* @param truncateMillisecond 是否毫秒归零
* @return 一天的结束时间
* @since 5.7.18
*/
public static LocalDateTime endOfDay(LocalDate date, boolean truncateMillisecond) {
if (truncateMillisecond) {
return LocalDateTime.of(date, LocalTime.of(23, 59, 59));
}
return LocalDateTime.of(date, LocalTime.MAX);
}

/**
* {@link TemporalAccessor}转换为 时间戳(从1970-01-01T00:00:00Z开始的毫秒数)
*
Expand Down

0 comments on commit 2f1583a

Please sign in to comment.