Java Convert Number of Days to Milliseconds

Tags: Java Duration Java 8

In this Java core tutorial we learn how to convert number of days to number of milliseconds in Java programming language.

How to convert number of days to milliseconds in Java

In Java, with a number of days we can use the java.time.Duration class to convert it to number of milliseconds as the following Java code.

ConvertDaysToMillisecondsExample1.java

import java.time.Duration;

public class ConvertDaysToMillisecondsExample1 {
    public static void main(String... args) {
        long numberOfDays = 365;

        // Convert number of days to milliseconds
        Duration duration = Duration.ofDays(numberOfDays);
        long milliseconds = duration.toMillis();

        System.out.println("Number of days: " + numberOfDays);
        System.out.println("Number of milliseconds: " + milliseconds);
    }
}
The output as below.
Number of days: 365
Number of milliseconds: 31536000000

Happy Coding 😊

Java Convert Number of Days to Hours

Java Convert Number of Days to Minutes

Java Convert Number of Days to Seconds