What is Duration.toDays() in Java?

toDays() is an instance method of the Duration class that is used to get the number of days in duration. This method returns the total number of days in the duration by dividing the number of seconds by 8640086400; this is based on the standard definition of a day as 2424 hours.

The toDays() method is defined in the Duration class. The Duration class is defined in the java.time package. To import the Duration class, use the following import statement.

import java.time.Duration;

Syntax


public long toDays()

Parameters

The method has no parameters.

Return value

The toDays() method returns the number of days in the duration.

Code

In the code below, we convert Duration class objects of different time units to days.

import java.time.Duration;
public class Main{
public static void main(String[] args) {
Duration durationInHours = Duration.ofHours(100); // Get number of seconds in 100 hours
System.out.println("100 hours in days - " + durationInHours.toDays());
Duration durationInMinutes = Duration.ofMinutes(10000); // Get number of seconds in 10000 minutes
System.out.println("10000 minutes in days - " + durationInMinutes.toDays());
}
}

Free Resources