java计时功能
思路:
1.在java中提供一个系统方法可以获取当前时间毫秒数;System.currentTimeMillis()
2.在需要的时候记录开始时的时间:long startMillis = System.currentTimeMillis();
3.在结束时在获取当前结束时间:long endMillis = System.currentTimeMillis();
4.计算差值
public class Demo1 { public static void main(String[] args) { double startMillis = System.currentTimeMillis(); for(int i=1; i<=10000; i++){ System.out.print(i + " "); if(i%10==0){ System.out.println(); } } double endMillis = System.currentTimeMillis(); double useTime = (endMillis - startMillis)/1000*0.1; System.out.println("耗时:" + useTime); } }