Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 6eff66a

Browse files
committed
add converter for date to timestamp
1 parent 9dcb100 commit 6eff66a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/main/java/com/zhazhapan/util/DateUtils.java

+54
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,60 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
1717

1818
private DateUtils() {}
1919

20+
/**
21+
* 将日期转换成时间戳
22+
*
23+
* @param date {@link Date}
24+
*
25+
* @return {@link Timestamp}
26+
*
27+
* @since 1.1.1
28+
*/
29+
public static Timestamp convertDateToTimestamp(Date date) {
30+
return convertDateToTimestamp(date, getCurrentTimestamp());
31+
}
32+
33+
/**
34+
* 将日期转换成时间戳
35+
*
36+
* @param date {@link Date}
37+
* @param elseValue 日期为空返回默认时间戳
38+
*
39+
* @return {@link Timestamp}
40+
*
41+
* @since 1.1.1
42+
*/
43+
public static Timestamp convertDateToTimestamp(Date date, Timestamp elseValue) {
44+
return Checker.isNull(date) ? elseValue : new Timestamp(date.getTime());
45+
}
46+
47+
/**
48+
* 将日期转换成时间
49+
*
50+
* @param date {@link Date}
51+
*
52+
* @return {@link Time}
53+
*
54+
* @since 1.1.1
55+
*/
56+
public static Time convertDateToTime(Date date) {
57+
return convertDateToTime(date, new Time(System.currentTimeMillis()));
58+
}
59+
60+
/**
61+
* 将日期转换成时间
62+
*
63+
* @param date {@link Date}
64+
* @param elseValue 日期为空返回默认时间
65+
*
66+
* @return {@link Time}
67+
*
68+
* @since 1.1.1
69+
*/
70+
public static Time convertDateToTime(Date date, Time elseValue) {
71+
return Checker.isNull(date) ? elseValue : new Time(date.getTime());
72+
}
73+
2074
/**
2175
* 第一个值是否大于第二个值
2276
*

0 commit comments

Comments
 (0)