// import java.time.*; Instant start = Instant.now(); // do something Instant end = Instant.now(); System.out.println("Duration in ms: " + Duration.between(start, end).toMillis());