Conversion.java
984 Bytes
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
package com.huaheng.api.SSP;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.sql.Date;
public class Conversion {
/**
* String转timestamp
* @param str
* @return
*/
public Timestamp strToDateLong(String str) {
Timestamp ts = new Timestamp(System.currentTimeMillis());
String tsStr = str;
try {
ts = Timestamp.valueOf(tsStr);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
/**
* Date转String
* @param tsp
* @return
*/
public String dateLongToStr(Date tsp){
String dateStr = "";
Date date = tsp;
//format的格式可以任意
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
dateStr = sdf.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
}