Sunday, 15 July 2012

bash - shell script: time difference -



bash - shell script: time difference -

this script count time difference between , date. there other way same operation more efficiently?

#!/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"

bash shell time

No comments:

Post a Comment