如何计算java程序运行花了多长时间。加时间戳。


 

1 long start = System.currentTimeMillis(); // 记录起始时间
2 try { 
3      Thread.sleep(5000);                     // 线程睡眠5秒,让运行时间不那么小
4    } catch (InterruptedException e) {
5             e.printStackTrace();
6        }
7 long end = System.currentTimeMillis();       // 记录结束时间
8 System.out.println(end-start);              // 相减得出运行时间

单位是毫秒。

long start = System.currentTimeMillis(); //获取当前时间

long end = System.currentTimeMillis();  

 

//System.nanoTime()   


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM