diff --git a/src/main/java/com/sipai/tools/CommUtil.java b/src/main/java/com/sipai/tools/CommUtil.java index 0b4e808..e543064 100644 --- a/src/main/java/com/sipai/tools/CommUtil.java +++ b/src/main/java/com/sipai/tools/CommUtil.java @@ -181,7 +181,17 @@ public class CommUtil { format = "yyyy-MM-dd HH:mm:ss"; } 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 { -