1.格林威治工夫转换成北京工夫(13位毫秒值转成时分秒)
1.1:先转成时分秒的格局,间接在小时上减少8小时
if (StringUtil.isNotEmpty(list)) {
String str = list.get(0).get("startTime").toString();
Date date = DateUtils.stringtoDate(str, "yyyy-MM-dd'T'HH:mm:ss.SSS");
date = DateUtils.addHour(date, 8);
String formatDate = DateUtils.dateToString(date, "yyyy-MM-dd HH:mm:ss.SSS");
list.get(0).put("startTime", formatDate);
return list.get(0);
}
1.2:间接转换成北京工夫(最初后果失去的13位毫秒值)
public static long tzToLong(String time){
time = time.replace("Z", " UTC");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date times = null;
try {
times = format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
String result = defaultFormat.format(times);
Date parse = null;
try {
parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(result);
} catch (ParseException e) {
e.printStackTrace();
}
Long milliTime = parse.getTime();
return milliTime;
}
2.时分秒转换成13位毫秒值(工夫戳)
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long time = date.getTime();
String milliTime = String.valueOf(time);
发表回复