// 放在要检测的代码段前,取开始前的时间戳
Long startTime = System.currentTimeMillis();

// 放在要检测的代码段前,取结束后的时间戳
Long endTime = System.currentTimeMillis();

// 计算并打印耗时
Long tempTime = (endTime - startTime);
System.out.println("花费时间:"+
(((tempTime/86400000)>0)?((tempTime/86400000)+"d"):"")+
((((tempTime/86400000)>0)||((tempTime%86400000/3600000)>0))?((tempTime%86400000/3600000)+"h"):(""))+
((((tempTime/3600000)>0)||((tempTime%3600000/60000)>0))?((tempTime%3600000/60000)+"m"):(""))+
((((tempTime/60000)>0)||((tempTime%60000/1000)>0))?((tempTime%60000/1000)+"s"):(""))+
((tempTime%1000)+"ms"));

相关文章:

  • 2022-12-23
  • 2021-09-15
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-26
  • 2021-10-15
  • 2022-02-16
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案