JDK1.8 LocalDateTime

判断LocalDateTime 时间大小

即返回long  就是判断long 即可 调用

Duration.between()
LocalDateTime time1= LocalDateTime.of(2018, 7, 9, 0, 0); //time1
LocalDateTime time2 = LocalDateTime.now();//time2
Duration duration = Duration.between(time1, time2);
Long timeRange = duration.toMillis(); //转化long
if (timeRange > 0) {
 
 
    //time1 > time2
} else {
//time1 < time2
}

时间增加  小时  天 月 年    还有很多不一一说明 具体之说这几个

LocalDateTime time = LocalDateTime.now();

LocalDateTime increaseTime = time.plusHours(1);//增加一小时

LocalDateTime increaseTime = time.plusDays(1);//增加一天

LocalDateTime increaseTime = time.plusMonths(1);//增加一月

LocalDateTime increaseTime = time.plusYears(1);//增加一年


猜你喜欢

转载自blog.csdn.net/beckhamyht/article/details/80910602