// 放在要检测的代码段前,取开始前的时间戳标签:Java,60000,3600000,System,代码运行,86400000,tempTime%,tempTime,统计 From: https://www.cnblogs.com/skytiger/p/17150399.html
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"));