派生自 projectDept/qhighschool

胡仁荣
2023-08-04 2174b22bbbb45284765a23b8189df59583c65d29
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.qxueyou.scc.base.util;
 
import java.sql.Time;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
 
import org.apache.commons.lang3.StringUtils;
 
/**
 * 提供日期或者是时间格式化处理工具类。
 *
 * @author 邓志永
 * @since JDK1.6
 * @history 2014-11-28 邓志永 新建
 */
public final class DateTimeFormatUtils {
    /** ISO_DATETIME_FORMAT*/
    public final static String ISO_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    /** ISO_DATE_FORMAT*/
    public final static String ISO_DATE_FORMAT = "yyyy-MM-dd";
    /** ISO_SHORT_DATE_FORMAT*/
    public final static String ISO_SHORT_DATE_FORMAT = "yyyy-MM";
    /** ISO_TIME_FORMAT*/
    public final static String ISO_TIME_FORMAT = "HH:mm:ss";
 
    private DateTimeFormatUtils() {
    }
 
    /**
     * 根据配置的默认日期时间格式来获取指定的对象的字符串信息。
     *
     * @param value
     *            需要被转换的日期时间对象引用。
     * @return 返回的是格式化后的字符串。
     */
    public static String formatDateTime(Timestamp value) {
        return formatDateTime(value, ISO_DATETIME_FORMAT);
    }
 
    /**
     * 根据配置的默认日期时间格式来获取指定的对象的字符串信息。
     *
     * @param value
     *            需要被转换的日期时间对象引用。
     * @param defaultFormat
     *            按照指定的格式来处理当前的日期时间对象。
     * @return 返回的是格式化后的字符串。
     */
    public static String formatDateTime(Timestamp value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATETIME_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
 
    public static String formatDate(Timestamp value) {
        return formatDateTime(value, ISO_DATE_FORMAT);
    }
 
    public static String formatDate(Timestamp value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
 
    public static String formatDate(java.sql.Date value) {
        return formatDate(value, ISO_DATE_FORMAT);
    }
 
    public static String formatDate(java.util.Date value) {
        return formatDate(value, ISO_DATE_FORMAT);
    }
 
    public static String formatDate(java.util.Date value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
 
    public static String formatDate(java.sql.Date value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
 
    public static String formatTime(Time value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_TIME_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
 
    public static String formatTime(Time value) {
        return formatTime(value, ISO_TIME_FORMAT);
    }
 
    public static String formatShortDate(Timestamp value) {
        return formatDateTime(value, ISO_SHORT_DATE_FORMAT);
    }
 
    public static String formatShortDate(Timestamp value, String defaultFormat) {
        if (value == null) {
            return "";
        }
        String strFormatStyle = StringUtils.isEmpty(defaultFormat) ? ISO_SHORT_DATE_FORMAT
                : defaultFormat;
        SimpleDateFormat objSimpleDateFormat = new SimpleDateFormat(strFormatStyle);
        return objSimpleDateFormat.format(value);
    }
 
}