Duration toHours() example
Description
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.
Syntax
toHours
has the following syntax.
public long toHours()
Example
The following example shows how to use toHours
.
import java.time.Duration;
import java.time.LocalTime;
/* ww w.j a v a 2s . com*/
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.