mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
DateUtil.date方法统一修改规则,传入null返回null
This commit is contained in:
parent
c64b38244b
commit
db108e1ca9
@ -14,6 +14,7 @@
|
||||
* 【db 】 AbstractDb添加返回类型为PageResult的page重载方法(pr#916@Gitee)
|
||||
* 【core 】 DesensitizedUtil增加对IPv4和IPv6支持(issue#I6ABCS@Gitee)
|
||||
* 【core 】 针对CollUtil.subtract coll1 为只读集合的补偿(pr#2865@Github)
|
||||
* 【core 】 DateUtil.date方法统一修改规则,传入null返回null(pr#2877@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复HexUtil.isHexNumber()对"-"的判断问题(issue#2857@Github)
|
||||
|
@ -68,11 +68,14 @@ public class DateUtil extends CalendarUtil {
|
||||
* {@link Date}类型时间转为{@link DateTime}<br>
|
||||
* 如果date本身为DateTime对象,则返回强转后的对象,否则新建一个DateTime对象
|
||||
*
|
||||
* @param date Long类型Date(Unix时间戳)
|
||||
* @param date Long类型Date(Unix时间戳),如果传入{@code null},返回{@code null}
|
||||
* @return 时间对象
|
||||
* @since 3.0.7
|
||||
*/
|
||||
public static DateTime date(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
if (date instanceof DateTime) {
|
||||
return (DateTime) date;
|
||||
}
|
||||
@ -82,11 +85,14 @@ public class DateUtil extends CalendarUtil {
|
||||
/**
|
||||
* 根据已有{@link Date} 产生新的{@link DateTime}对象
|
||||
*
|
||||
* @param date Date对象
|
||||
* @param date Date对象,如果传入{@code null},返回{@code null}
|
||||
* @return {@link DateTime}对象
|
||||
* @since 4.3.1
|
||||
*/
|
||||
public static DateTime dateNew(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime(date);
|
||||
}
|
||||
|
||||
@ -105,10 +111,13 @@ public class DateUtil extends CalendarUtil {
|
||||
* {@link Calendar}类型时间转为{@link DateTime}<br>
|
||||
* 始终根据已有{@link Calendar} 产生新的{@link DateTime}对象
|
||||
*
|
||||
* @param calendar {@link Calendar}
|
||||
* @param calendar {@link Calendar},如果传入{@code null},返回{@code null}
|
||||
* @return 时间对象
|
||||
*/
|
||||
public static DateTime date(Calendar calendar) {
|
||||
if (calendar == null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTime(calendar);
|
||||
}
|
||||
|
||||
@ -116,7 +125,7 @@ public class DateUtil extends CalendarUtil {
|
||||
* {@link TemporalAccessor}类型时间转为{@link DateTime}<br>
|
||||
* 始终根据已有{@link TemporalAccessor} 产生新的{@link DateTime}对象
|
||||
*
|
||||
* @param temporalAccessor {@link TemporalAccessor},常用子类: {@link LocalDateTime}、 LocalDate
|
||||
* @param temporalAccessor {@link TemporalAccessor},常用子类: {@link LocalDateTime}、 LocalDate,如果传入{@code null},返回{@code null}
|
||||
* @return 时间对象
|
||||
* @since 5.0.0
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user