Java Date Time - Duration toDays() example








Duration toDays() gets the number of days in this duration.

This returns the total number of days in the duration by dividing the number of seconds by 86400.

Syntax

toDays has the following syntax.

public long toDays()

Example

The following example shows how to use toDays.

import java.time.Duration;
import java.time.LocalTime;
//from   w  ww.  ja  va 2 s.  c  o  m
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.toDays());
    
  }
}

The code above generates the following result.