This repository was archived by the owner on Nov 21, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-9
lines changed
src/main/java/org/code4everything/boot/base Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import cn .hutool .core .date .DateUtil ;
4
4
5
- import java .time .Instant ;
6
5
import java .time .LocalDate ;
7
6
import java .time .LocalDateTime ;
8
7
import java .time .ZoneId ;
@@ -68,26 +67,37 @@ private DateUtils() {}
68
67
* @since 1.1.6
69
68
*/
70
69
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 ());
74
84
}
75
85
76
86
/**
77
87
* 日期互转
78
88
*
79
89
* @param date {@link Date}
80
90
*
81
- * @return {@link LocalDate }
91
+ * @return {@link LocalDateTime }
82
92
*
83
93
* @since 1.1.6
84
94
*/
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 ());
89
97
}
90
98
99
+ // ------------------------------------------------分割线------------------------------------------------------------
100
+
91
101
/**
92
102
* 获取本年的开始时间点
93
103
*
You can’t perform that action at this time.
0 commit comments