Java Convert Number of Seconds to Milliseconds
Tags: Java Duration Java 8
In this Java tutorial we learn how to convert number of seconds into milliseconds using the java.time.Duration class in Java programming language.
How to convert number of seconds to milliseconds in Java
In Java, with a given number of seconds we can use the Duration.toMillis() method to convert it to milliseconds value as the following Java program.
ConvertSecondsToMillisecondsExample.java
import java.time.Duration;
public class ConvertSecondsToMillisecondsExample {
public static void main(String... args) {
long numberOfSeconds = 10;
// Convert Number of Seconds to Milliseconds
long numberOfMilliseconds = Duration.ofSeconds(numberOfSeconds).toMillis();
System.out.println("Number of seconds: " + numberOfSeconds);
System.out.println("Number of milliseconds: " + numberOfMilliseconds);
}
}
Number of seconds: 10
Number of milliseconds: 10000
Happy Coding 😊
Related Articles
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 Nanoseconds
Java Convert Number of Milliseconds to Nanoseconds
Java Convert Number of Days to Nanoseconds
Java Convert Number of Hours to Minutes
Java Convert Number of Hours to Seconds