This repository was archived by the owner on Jan 24, 2019. It is now read-only.
File tree 1 file changed +34
-0
lines changed
src/main/java/com/zhazhapan/util
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .zhazhapan .util ;
2
2
3
+ import cn .hutool .core .date .DateUtil ;
4
+ import com .zhazhapan .modules .constant .ValueConsts ;
5
+ import org .junit .Assert ;
6
+
3
7
import java .sql .Time ;
4
8
import java .sql .Timestamp ;
5
9
import java .text .ParseException ;
@@ -17,6 +21,36 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
17
21
18
22
private DateUtils () {}
19
23
24
+ /**
25
+ * 解析时间字符串
26
+ *
27
+ * @param time 时间
28
+ *
29
+ * @return {@link Time}
30
+ *
31
+ * @since 1.1.1
32
+ */
33
+ public static Time parseTime (String time ) {
34
+ Assert .assertTrue ("time is required, but value is empty" , Checker .isNotEmpty (time ));
35
+ String [] times = time .split (ValueConsts .COLON );
36
+ String timeStr = formatTimeString (times [0 ]) + ":" + (times .length > 1 ? formatTimeString (times [1 ]) : "00" ) +
37
+ ":" + (times .length > 2 ? formatTimeString (times [2 ]) : "00" );
38
+ return new Time (DateUtil .parseTime (timeStr ).getTime ());
39
+ }
40
+
41
+ /**
42
+ * 格式化字符串
43
+ *
44
+ * @param time 时间
45
+ *
46
+ * @return {@link String}
47
+ *
48
+ * @since 1.1.1
49
+ */
50
+ private static String formatTimeString (String time ) {
51
+ return time .length () > 0 ? (time .length () == 1 ? "0" : "" ) + time : "00" ;
52
+ }
53
+
20
54
/**
21
55
* 将日期转换成时间戳
22
56
*
You can’t perform that action at this time.
0 commit comments