通过给定的秒级时间戳,来算出n天后的时间戳,或者是字符串
java8之前的时间api存在闰秒问题,所以如果要获取到准确的时间戳,最好用java8api,不要用当前时间戳加上每天的秒数来算.
private String getDelayDaysString(Long stratTime, Integer n) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(stratTime), getChinaZone());
LocalDateTime time = localDateTime.plusDays(n);
return time.toString();
}
private static ZoneOffset getChinaZone() {
return ZoneOffset.of("+8");
}
本文介绍如何使用Java8 API准确计算从给定秒级时间戳开始的n天后的时间戳,避免了传统方法中可能遇到的闰秒问题,提供了具体实现代码。
1115

被折叠的 条评论
为什么被折叠?



