Calculating time difference in Milliseconds

前端 未结 9 523
谎友^
谎友^ 2020-12-04 21:42

I am making a call to a method by passing ipAddress and it will return back the location of ipAddress like Country, City, etc etc. So I was trying to see how much time it is

9条回答
  •  天命终不由人
    2020-12-04 22:09

    From Java 8 onward you can try the following:

    import java.time.*;
    import java.time.temporal.ChronoUnit;
    
    Instant start_time = Instant.now();
    // Your code
    Instant stop_time = Instant.now();
    
    System.out.println(Duration.between(start_time, stop_time).toMillis());
    
    //or
    
    System.out.println(ChronoUnit.MILLIS.between(start_time, stop_time));
    

提交回复
热议问题