Shell 脚本计算时间差

在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"

 

posted @ 2017-01-13 10:10  Reynold.C  Views(26989)  Comments(0Edit  收藏  举报