TimestampUtils.java
1.68 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
package com.share.mvpsdk.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class TimestampUtils {
/**
* 获取当前的时间戳,时区为北京
*
* @return
*/
public static String getCurrentTimestamp() {
//时间戳的格式必须为 yyyy-MM-dd HH:mm:ss
String timestamp = null;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
timestamp = format.format(new Date());
return timestamp;
}
/**
* 获取当前的时间戳,时区为北京
*
* @return
*/
public static String getCurrentTime(long times) {
//时间戳的格式必须为 yyyy-MM-dd HH:mm:ss
Date date = new Date(Long.valueOf(times));
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
String time = format.format(date);
LogUtils.e("timetimetimetimetimetimetime为:" + time);
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date());
return time;
}
//法国时间:东一区
public static String getDateTimeByGMT(int timeZone) {
SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
switch (timeZone) {
case 1:
dff.setTimeZone(TimeZone.getTimeZone("GMT+1"));
break;
case 8:
dff.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//LogUtils.i("采用东八区时区");
break;
}
String time = dff.format(new Date());
//LogUtils.i("东八区时区时间为--》》" + time);
return time;
}
}