有时候需要用到计算程序运行的时间,每次都是直接用System.currentTimeMillis()或者另外一个纳秒的.觉得比较麻烦,就写了一个简单的工具,大神勿喷,有好的建议欢迎留言.
package com.wk.mothod; public class MyTimeUtil { private long time=0; public void start() { time=System.currentTimeMillis(); } public void end(){ time=System.currentTimeMillis()-time; } public long endAndGet(){ time=System.currentTimeMillis()-time; return time; } public long getTime(){ return time; } public void disp() { System.out.println("The total time is:"+time+"ms"); } public void endAndDisp() { time=System.currentTimeMillis()-time; System.out.println("The total time is:"+time+"ms"); } }
时间: 2024-10-14 15:33:14