Shell script calculates time difference

Excerpt from: https://www.cnblogs.com/leixingzhi7/p/6281675.html

The time required to complete the execution of the statistical program in the shell script is not as convenient as using System.currentTimeMillis () in java

Record it a bit for backup, so as not to spend time again (counting how many s the program execution consumes):

 

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"

 

The time required to complete the execution of the statistical program in the shell script is not as convenient as using System.currentTimeMillis () in java

Record it a bit for backup, so as not to spend time again (counting how many s the program execution consumes):

 

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"

 

Guess you like

Origin www.cnblogs.com/LiuYanYGZ/p/12724203.html