Shell 脚本计算时间差

摘自:https://www.cnblogs.com/leixingzhi7/p/6281675.html

在shell脚本中统计程序执行完毕所需要的时间不像在java中使用System.currentTimeMillis()方便

稍微记录一下,以供备用,免得又去花时间想(统计程序执行消耗多少s):

starttime=`date +'%Y-%m-%d %H:%M:%S'`
#执行程序
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次运行时间: "$((end_seconds-start_seconds))"s"
原文地址:https://www.cnblogs.com/LiuYanYGZ/p/12724203.html