puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.stylefeng.guns.core.support;
 
import java.util.Date;
 
/**
 * 封装java.util.Date
 * @author xiaoleilu
 *
 */
public class DateTime extends Date{
    private static final long serialVersionUID = -5395712593979185936L;
    
    /**
     * 转换JDK date为 DateTime
     * @param date JDK Date
     * @return DateTime
     */
    public static DateTime parse(Date date) {
        return new DateTime(date);
    }
    
    /**
     * 当前时间
     */
    public DateTime() {
        super();
    }
    
    /**
     * 给定日期的构造
     * @param date 日期
     */
    public DateTime(Date date) {
        this(date.getTime());
    }
    
    /**
     * 给定日期毫秒数的构造
     * @param timeMillis 日期毫秒数
     */
    public DateTime(long timeMillis) {
        super(timeMillis);
    }
    
    @Override
    public String toString() {
        return DateTimeKit.formatDateTime(this);
    }
    
    public String toString(String format) {
        return DateTimeKit.format(this, format);
    }
    
    /**
     * @return 输出精确到毫秒的标准日期形式
     */
    public String toMsStr() {
        return DateTimeKit.format(this, DateTimeKit.NORM_DATETIME_MS_PATTERN);
    }
    
    /**   
     * @return java.util.Date
    */
    public Date toDate() {
        return new Date(this.getTime());
    }
}