Java时间方法执行


Java时间方法执行

import java.util.Calendar;

public class Tester {

   public static void main(String[] args) {

      long startTime = Calendar.getInstance().getTimeInMillis();

      longRunningMethod();

      long endTime = Calendar.getInstance().getTimeInMillis();

      System.out.println("Time taken: " + (endTime - startTime) + " ms");

   }

   public static void longRunningMethod() {

      try {

         Thread.sleep(1000);

      } catch (InterruptedException e) {

         e.printStackTrace();

      }

   }

}