[java] How do I time a method's execution in Java?

Using Instant and Duration from Java 8's new API,

Instant start = Instant.now();
Thread.sleep(5000);
Instant end = Instant.now();
System.out.println(Duration.between(start, end));

outputs,

PT5S