派生自 projectDept/qhighschool

Administrator
2022-11-18 b6a92bcd70d2edfb8bf2a2e784b37e1fcd036c10
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);
    }
 
}