Example usage for java.time Duration abs

List of usage examples for java.time Duration abs

Introduction

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

Prototype

public Duration abs() 

Source Link

Document

Returns a copy of this duration with a positive length.

Usage

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON);
    System.out.println(duration.abs());

}

From source file:Main.java

public static void main(String[] args) {
    Instant firstInstant = Instant.ofEpochSecond(1294881180);
    Instant secondInstant = Instant.ofEpochSecond(1294708260);

    Duration between = Duration.between(firstInstant, secondInstant);

    System.out.println(between);/*  w w  w . ja v a 2  s  .co m*/

    long seconds = between.getSeconds();

    long absoluteResult = between.abs().toMinutes();

}

From source file:nu.yona.server.analysis.service.AnalysisEngineService.java

private Duration determineDeviceTimeOffset(AppActivitiesDto appActivities) {
    Duration offset = Duration.between(ZonedDateTime.now(), appActivities.getDeviceDateTime());
    return (offset.abs().compareTo(DEVICE_TIME_INACCURACY_MARGIN) > 0) ? offset : Duration.ZERO; // Ignore if less than 10
    // seconds/*from  w w w  . j  av  a 2  s .c  o  m*/
}