Java Convert Number of Days to Seconds

Tags: Java Duration Java 8

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

How to convert number of days to seconds in Java

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

ConvertDaysToSecondsExample1.java

import java.time.Duration;

public class ConvertDaysToSecondsExample1 {
    public static void main(String... args) {
        long numberOfDays = 7;

        // Convert number of days to seconds
        Duration duration = Duration.ofDays(numberOfDays);
        long numberOfSeconds = duration.toSeconds();

        System.out.println("Number of days: " + numberOfDays);
        System.out.println("Number of seconds: " + numberOfSeconds);
    }
}
The output as below.
Number of days: 7
Number of seconds: 604800

Happy Coding 😊

Java Convert Number of Days to Hours

Java Convert Number of Days to Minutes

Java Convert Number of Days to Milliseconds