java8时间api:LocalDateTime

通过给定的秒级时间戳,来算出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");
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章