取下一个一分钟和五分钟的秒数

//下一个1分钟的秒数

LocalDateTime currentTime = LocalDateTime.now();
LocalDateTime nextMinute = currentTime.plusMinutes(1).truncatedTo(ChronoUnit.MINUTES);
long between = ChronoUnit.SECONDS.between(currentTime, nextMinute);



//下一个五分钟的秒数
LocalDateTime currentTime = LocalDateTime.now();

LocalDateTime nextFiveMinute = currentTime.plusMinutes(5 - (currentTime.getMinute() % 5))
.truncatedTo(ChronoUnit.MINUTES);
long remainingTimeInSeconds = ChronoUnit.SECONDS.between(currentTime, nextFiveMinute);

System.out.println("当前时间: " + currentTime);
System.out.println("下一个五分钟的时间: " + nextFiveMinute);
System.out.println("剩余时间(秒): " + remainingTimeInSeconds);
posted @ 2023-08-29 10:58  异想天开的carlors  阅读(51)  评论(0)    收藏  举报