Java Convert Number of Hours to Milliseconds
Tags: Java Duration Java 8
In this Java core tutorial, we learn how to convert a number of hours to milliseconds using the java.time.Duration class in Java programming language.
How to convert number of hours to milliseconds in Java
In Java, with a given number of hours we can use the Duration.toMillis() method to convert it to milliseconds value as the example Java code below.
ConvertHoursToMillisecondsExample.java
import java.time.Duration;
public class ConvertHoursToMillisecondsExample {
public static void main(String... args) {
long numberOfHours = 4;
// Convert Number of Hours to Milliseconds
long numberOfMilliseconds = Duration.ofHours(numberOfHours).toMillis();
System.out.println("Number of hours: " + numberOfHours);
System.out.println("Number of milliseconds: " + numberOfMilliseconds);
}
}
Number of hours: 4
Number of milliseconds: 14400000
Happy Coding 😊
Related Articles
Java Convert Number of Days to Nanoseconds
Java Convert Number of Hours to Minutes
Java Convert Number of Hours to Seconds
Java Convert Number of Hours to Nanoseconds
Java Convert Number of Minutes to Seconds
Java Convert Number of Minutes to Milliseconds
Java Convert Number of Minutes to Nanoseconds
Java Convert Number of Seconds to Milliseconds