package Demo; import java.util.*; import java.io.*; public class loop { public static void main(String[] args) { try{//获取当前时间,以及sleep long start = System.currentTimeMillis(); for (int i = 0; i<5; i++){ Thread.sleep(1000); System.out.println(i); } long end = System.currentTimeMillis(); long diff = (end - start)/1000; System.out.println("。。。。。"+diff); }catch (Exception e){ e.printStackTrace(); System.out.println(e); } } }