How to get the milliseconds to the next hour in Java

1 Answer

0 votes
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.time.Duration;

public class MyClass {
    public static void main(String args[]) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime end = now.plusHours(1).truncatedTo(ChronoUnit.HOURS);

        Duration duration = Duration.between(now, end);
        
        long milliseconds = duration.toMillis();  
                 
        System.out.println(milliseconds);
    }
}
     
     
     
     
/*
run:
 
2934188
     
*/

 



answered Mar 19, 2021 by avibootz
...