这是我的脚本来计算现在和我的约会之间的时差。 有没有其他方法可以更有效地进行相同的操作?
#!/bin/bash
mydate=20141224 # yyyymmdd
mytime=00:00:00 #hh:mm:ss
current=$(date +%s)
target=$(date -d "$mydate $mytime" +%s)
diff=$((target-current))
day=$((diff / 86400))
left=$((diff - (day*86400)))
diff=$((left))
hour=$((diff / 3600))
left=$((diff - (hour * 3600)))
diff=$((left))
min=$((diff / 60))
left=$((diff -(min * 60)))
diff=$((left))
sec=$((diff))
echo $day"d" $hour"h" $min"min" $sec"sec"