timestamp 转 date 少一天

timestamp 时间为 GMT

而我们数据库大都设置时区GMT+8

1
2
3
4
5
6
7
8
9
10
11
12
13

/**
* 根据long类型时间戳 获取当前date 添加时区判断
* @param timestamp
* @return
*/
public static Date getDateByLongTime(Long timestamp){

TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
c.setTime(new Date(timestamp));
return c.getTime();
}