Example usage for java.time Duration between

List of usage examples for java.time Duration between

Introduction

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

Prototype

public static Duration between(Temporal startInclusive, Temporal endExclusive) 

Source Link

Document

Obtains a Duration representing the duration between two temporal objects.

Usage

From source file:org.kitodo.production.services.data.ProcessService.java

/**
 * Calculate and return duration/age of given process as a String.
 *
 * @param process ProcessDTO object for which duration/age is calculated
 * @return process age of given process// w  w w.j  a v a2  s  . c  o  m
 */
public static String getProcessDuration(ProcessDTO process) {
    String creationDateTimeString = process.getCreationDate();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    LocalDateTime createLocalDate = LocalDateTime.parse(creationDateTimeString, formatter);
    Duration duration = Duration.between(createLocalDate, LocalDateTime.now());
    return String.format("%sd; %sh", duration.toDays(),
            duration.toHours() - TimeUnit.DAYS.toHours(duration.toDays()));
}

From source file:org.openecomp.sdc.be.model.operations.impl.ComponentOperation.java

public Either<List<ComponentInstance>, StorageOperationStatus> getAllComponentInstncesMetadata(
        String componentId, NodeTypeEnum nodeType) {
    Instant start = Instant.now();
    Either<List<ComponentInstance>, StorageOperationStatus> resourceInstancesOfService = componentInstanceOperation
            .getAllComponentInstancesMetadataOnly(componentId, nodeType);
    Instant end = Instant.now();
    log.debug("TOTAL TIME BL GET INSTANCES: {}", Duration.between(start, end)); // prints
    // PT1M3.553S
    return resourceInstancesOfService;
}