forked from zhangchuangiie/SimpleMybatis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatTimeUtil.java
More file actions
76 lines (50 loc) · 2.05 KB
/
FormatTimeUtil.java
File metadata and controls
76 lines (50 loc) · 2.05 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
package com.example.demo.util;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.LinkedHashMap;
import java.util.List;
public class FormatTimeUtil {
public static String timeStamp2DateString(Timestamp timeStamp) {
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return fm.format(timeStamp);
}
public static int formatTimeOfListMap(List<LinkedHashMap<String, Object>> result,String formatKey) {
int n = 0;
for (LinkedHashMap<String, Object> m : result) {
for (String k : m.keySet()) {
//System.out.println(k + " : " + m.get(k));
if (formatKey.equals(k)) {
m.put(k, timeStamp2DateString((Timestamp) m.get(k)));
n++;
}
}
}
return n;
}
public static int formatTimeOfListMap(List<LinkedHashMap<String, Object>> result) {
int n = 0;
for (LinkedHashMap<String, Object> m : result) {
for (String k : m.keySet()) {
//System.out.println(k + " : " + m.get(k));
//System.out.println(m.get(k).getClass().getName());
if (m.get(k) != null && "java.sql.Timestamp".equals(m.get(k).getClass().getName())) {
m.put(k, timeStamp2DateString((Timestamp) m.get(k)));
n++;
}
}
}
return n;
}
public static int formatTimeOfObjectMap(LinkedHashMap<String, Object> result) {
int n = 0;
for (String k : result.keySet()) {
//System.out.println(k + " : " + result.get(k));
//System.out.println(result.get(k).getClass().getName());
if (result.get(k) != null && "java.sql.Timestamp".equals(result.get(k).getClass().getName())) {
result.put(k, timeStamp2DateString((Timestamp) result.get(k)));
n++;
}
}
return n;
}
}