Java Convert Number of Days to Nanoseconds

Tags: Java Duration Java 8

In this Java core tutorial, we learn how to convert a number of days value to number of nanoseconds using the java.time.Duration class in Java programming language.

How to convert number of days to nanoseconds in Java

In Java, with a given number of days we can use the Duration.toNanos() method to convert it to number of nanoseconds value as the following Java code.

ConvertDaysToNanosecondsExample.java

import java.time.Duration;

public class ConvertDaysToNanosecondsExample {
    public static void main(String... args) {
        long numberOfDays = 5;

        // Convert Number of Days to Nanoseconds
        long numberOfNanoseconds = Duration.ofDays(numberOfDays).toNanos();

        System.out.println("Number of days: " + numberOfDays);
        System.out.println("Number of nanoseconds: " + numberOfNanoseconds);
    }
}
The output as below.
Number of days: 5
Number of nanoseconds: 432000000000000

Happy Coding 😊

Java Convert Number of Hours to Minutes

Java Convert Number of Hours to Seconds

Java Convert Number of Hours to Milliseconds

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

Java Convert Number of Seconds to Nanoseconds

Java Convert Number of Milliseconds to Nanoseconds