Example usage for java.time Duration plusHours

List of usage examples for java.time Duration plusHours

Introduction

In this page you can find the example usage for java.time Duration plusHours.

Prototype

public Duration plusHours(long hoursToAdd) 

Source Link

Document

Returns a copy of this duration with the specified duration in hours added.

Usage

From source file:Main.java

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());

}

From source file:com.vmware.vchs.base.DbaasApi.java

protected long getCycleAsSeconds(String cycle) {
    checkNotNull(cycle);/* w  w w. ja  v a2  s  .c  om*/
    String[] cycleValues = cycle.split(":");
    int length = cycleValues.length;
    Duration seconds;
    if (length == 4) {
        Duration days = Duration.ofDays(Long.parseLong(cycleValues[length - 4]));
        Duration hours = days.plusHours(Long.parseLong(cycleValues[length - 3]));
        Duration minutes = hours.plusMinutes(Long.parseLong(cycleValues[length - 2]));
        seconds = minutes.plusSeconds(Long.parseLong(cycleValues[length - 1]));
    } else {
        throw new FailException("Invalid cycle value" + cycle);
    }
    return seconds.getSeconds();
}