Skip to content
This repository was archived by the owner on Nov 21, 2020. It is now read-only.

Commit 0e2230c

Browse files
committed
fix: local date converter
1 parent 2977ed4 commit 0e2230c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/main/java/org/code4everything/boot/base/DateUtils.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import cn.hutool.core.date.DateUtil;
44

5-
import java.time.Instant;
65
import java.time.LocalDate;
76
import java.time.LocalDateTime;
87
import java.time.ZoneId;
@@ -68,26 +67,37 @@ private DateUtils() {}
6867
* @since 1.1.6
6968
*/
7069
public static Date toDate(LocalDate localDate) {
71-
ZoneId zone = ZoneId.systemDefault();
72-
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
73-
return Date.from(instant);
70+
return toDate(localDate.atStartOfDay());
71+
}
72+
73+
/**
74+
* 日期互转
75+
*
76+
* @param localDateTime {@link LocalDateTime}
77+
*
78+
* @return {@link Date}
79+
*
80+
* @since 1.1.6
81+
*/
82+
public static Date toDate(LocalDateTime localDateTime) {
83+
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
7484
}
7585

7686
/**
7787
* 日期互转
7888
*
7989
* @param date {@link Date}
8090
*
81-
* @return {@link LocalDate}
91+
* @return {@link LocalDateTime}
8292
*
8393
* @since 1.1.6
8494
*/
85-
public static LocalDate toLocalDate(Date date) {
86-
Instant instant = date.toInstant();
87-
ZoneId zone = ZoneId.systemDefault();
88-
return LocalDateTime.ofInstant(instant, zone).toLocalDate();
95+
public static LocalDateTime toLocalDateTime(Date date) {
96+
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
8997
}
9098

99+
// ------------------------------------------------分割线------------------------------------------------------------
100+
91101
/**
92102
* 获取本年的开始时间点
93103
*

0 commit comments

Comments
 (0)