-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataUtils
More file actions
92 lines (84 loc) · 2.38 KB
/
DataUtils
File metadata and controls
92 lines (84 loc) · 2.38 KB
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
public class FtspDateUtil {
private static final Log log = LogFactory.getLog(FtspDateUtil.class);
/** yyyy-MM-dd HH:mm:ss。 */
public static final String FORMAT_YMD_H24MS = "yyyy-MM-dd HH:mm:ss" ;
/** yyyy-MM-dd。 */
public static final String FORMAT_YMD = "yyyy-MM-dd" ;
/** yyyy年MM月dd日。 */
public static final String FORMAT_YMD_CN = "yyyy年MM月dd日" ;
/** yyyyMMdd。 */
public static final String FORMAT_YMD_TI = "yyyyMMdd" ;
/** yyyyMM。*/
public static final String FORMAT_YM = "yyyyMM" ;
/** yyyy-MM。*/
public static final String FORMAT_Y_M = "yyyy-MM";
/**
* 这个类不能实例化。
*/
private FtspDateUtil(){}
/**
* 获取年月日当前时间。
* @return String
*/
public static String getCurrTime() {
return parseDate(new Date(), FORMAT_YMD_H24MS);
}
/**
* 获取年月日当前时间 yyyyMMddHHmmss。
* @return String
*/
public static String getCurrTimeNoSeparator(){
String dateStr = getCurrTime();
return dateStr.replaceAll("-","").replaceAll(" ","").replaceAll(":","");
}
/**
* 获取年月日当前时间。
* @return String
*/
public static String getCurrDate() {
return parseDate(new Date(),FORMAT_YMD);
}
/**
* 获取年月日当前时间。
* @return String
*/
public static String getCurrDateNoSep() {
return parseDate(new Date(),FORMAT_YMD_TI);
}
private static Date getLastDateOfQuater(int year, int month) {
Calendar calendar = Calendar.getInstance();
//设置年份
calendar.set(Calendar.YEAR,year);
switch (month){
case 1:
case 2:
case 3:
month = 2;
break;
case 4:
case 5:
case 6:
month = 5;
break;
case 7:
case 8:
case 9:
month = 8;
break;
case 10:
case 11:
case 12:
month = 11;
break;
default :
month = 2;
}
//设置月份
calendar.set(Calendar.MONTH, month);
//获取某月最大天数
int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//设置日历中月份的最大天数
calendar.set(Calendar.DAY_OF_MONTH, lastDay);
return calendar.getTime();
}
}