timestamp 兼容秒和毫秒
This commit is contained in:
@ -181,7 +181,17 @@ public class CommUtil {
|
|||||||
format = "yyyy-MM-dd HH:mm:ss";
|
format = "yyyy-MM-dd HH:mm:ss";
|
||||||
}
|
}
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||||
return sdf.format(new Date(Long.valueOf(seconds)));
|
String timestamp = seconds.trim();
|
||||||
|
int dotIndex = timestamp.indexOf('.');
|
||||||
|
if (dotIndex > -1) {
|
||||||
|
timestamp = timestamp.substring(0, dotIndex);
|
||||||
|
}
|
||||||
|
long timeValue = Long.parseLong(timestamp);
|
||||||
|
// 兼容秒级和毫秒级时间戳:10位附近按秒处理,13位附近按毫秒处理。
|
||||||
|
if (Math.abs(timeValue) < 100000000000L) {
|
||||||
|
timeValue = timeValue * 1000L;
|
||||||
|
}
|
||||||
|
return sdf.format(new Date(timeValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,4 +252,3 @@ public class CommUtil {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user