package com.gcl.tools;
public class ExecutionTime {
public String PrintDate(Long startTime, Long endTime, String note){
// 计算并打印耗时
Long tempTime = (endTime - startTime);
String result = note + (((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");
System.out.println(result);
return result;
}
public static void main(String[] args) {
// 代码运行开始时间
Long startTime = System.currentTimeMillis();
// 代码运行结束时间
Long endTime = System.currentTimeMillis();
// 打印说明
String note = "程序执行时长";
new ExecutionTime().PrintDate(startTime, endTime, note);
}
}
打印java代码执行时间
于 2022-03-22 15:34:14 首次发布