2021年9月17日11:49:57 星期五
#!/bin/bash
#########################################################
# File name : date_diff.sh #
# Platform :All Linux Based Platform #
# Version :1.0 #
# Date :2021-09-17 #
# Author : Apple #
# Contact : #
# Company : #
#########################################################
start=$1
end=$2
startDate=`date -d "${start}" +%s`
endDate=`date -d "${end}" +%s`
t=`expr $endDate - $startDate`
dayDiff=`expr $t / 86400`
t=`expr $t % 86400`
hourDiff=`expr $t / 3600`
t=`expr $t % 3600`
minuteDiff=`expr $t / 60`
secondDiff=`expr $t % 60`
echo dayDiff=${dayDiff}-${hourDiff}:${minuteDiff}:${secondDiff}
示例
[11:57:58][apple]$./date_diff.sh 'Tue Sep 7 21:07:59 CST 2021' 'Fri Sep 17 09:57:17 CST 2021'
dayDiff=9-12:49:18