/**
*将时间戳转换成年月日时的时间格式
*/
public static String getDateStrWithHms(long time){
String result = null;
Date date = new Date(time);
String output = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(output, Locale.CHINESE);
result = simpleDateFormat1.format(date);
return result;
}
比如,上边这段代码,假设需要转换的时间戳是 1576041900秒,如果系统的时区设置成GMT+8,则转换出来的时间是:2019-12-11 13:25:00。如果系统时区设置成GMT+9,则转换出来的时间是2019-12-11 14:25:00。如果系统时区设置成GMT+10,则转换出来的时间是 2019-12-11 15:25:00