Example usage for java.time Duration toString

List of usage examples for java.time Duration toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

A string representation of this duration using ISO-8601 seconds based representation, such as PT8H6M12.345S .

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());
    System.out.println(duration.toString());
}

From source file:com.drunkendev.io.recurse.tests.RecursionTest.java

/**
 * Times a {@link Runnable} instance.//from  ww w.  ja  va2 s.  c om
 *
 * @param   r
 *          {@link Runnable} object to time.
 * @return  {@link Duration} object containing run-time length.
 */
public Duration time(Runnable r) {
    Instant start = Instant.now();
    r.run();
    Duration dur = Duration.between(start, Instant.now());
    System.out.format("Completed in: %s%n", dur.toString());
    return dur;
}