JAVA中如何使用计时函数?
还有,调用系统时间函数是什么?如何使用?

解决方案 »

  1.   

    long start = System.currentMillSeconds();
    long end = System.currentMillSeconds();
    long costtime = end - start;
      

  2.   

    在你计时开始的地方写下代码:
      long start = System.currentTimeMillis();
      //表示定义当前系统时间,单位:毫秒
    在你计时结束的地方写下下面的代码:
      long end = System.currentTimeMillis();
    所有程序运行的时间数(毫秒)为:
      long useTime = end - start;如新开10000个Double所需时间计算:
      long start = System.currentTimeMillis();
      //代码开始
      for(int i=0;i<10000;i++){
        Double a = new Double(i);
      }
      //代码结束
      long end = System.currentTimeMillis();
      //运行代码总用时:
      long useTime = end - start;
    从来没这么仔细写过,如果再看不懂,我也没办法了。
      

  3.   

    javax.swing.Timer timer = new javax.swing.Timer(1000,
     new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
    System.out.println("timer");
    }
    }