Duration toHours()
gets the number of hours in this duration.
This returns the total number of hours in the duration by dividing the number of seconds by 3600.
toHours
has the following syntax.
public long toHours()
The following example shows how to use toHours
.
import java.time.Duration; import java.time.LocalTime; //from w w w .jav a2 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.toHours()); } }
The code above generates the following result.