返回顶部

[shell]计算程序运行时常

实现

#!/bin/bash
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 @ 2021-07-18 18:45  Swetchine  阅读(131)  评论(0)    收藏  举报