Duration plusHours(long hoursToAdd) example
Description
Duration plusHours(long hoursToAdd)
returns a copy of
this duration with the specified duration in hours added.
This instance is immutable and unaffected by this method call.
Syntax
plusHours
has the following syntax.
public Duration plusHours(long hoursToAdd)
Example
The following example shows how to use plusHours
.
import java.time.Duration;
import java.time.LocalTime;
/* www . ja va 2 s . c om*/
public class Main {
public static void main(String[] args) {
Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
System.out.println(duration.getSeconds());
duration = duration.plusHours(4);
System.out.println(duration.getSeconds());
}
}
The code above generates the following result.