简体   繁体   中英

GeekTool (UNIX) counter leading zeros

I'm trying to make a timing counter for a running race through GeekTool on Mac (UNIX based) and have the following:

expr `date -j -f "%d/%m/%Y %H:%M:%S" "05/09/2012 07:41:15" "+%s"` - `date "+%s"` | awk '{ if( int( 0$1/86400 ) < 0 ) printf "" , int( 0$1/86400 ) ; if( int( 0$1/86400 ) < 0 || int( $1%86400/3600 ) < 0 ) printf "%d:" , int( $1%86400/3600 ) ; if( int( $1/86400 ) < 0 || int( $1%86400/3600 ) < 0 || int( $1%3600/60 ) < 0) printf "%d:" ,  int( $1%3600/60 ) ; if( int( $1/86400 ) < 0 || int( $1%86400/3600 ) < 0 || int( $1%3600/60 ) < 0 || $1%60 < 0 ) printf "%d" , $1%60 ; else printf "Hello!" }' | sed -E 's/-/ /' | sed -E 's/-/ /' | sed -E 's/-/ /' | sed -E 's/-/ /'

The problem is that when either the minutes or second are less than 10 there is no leading zero (ie 1:7 instead of 01:07). How do I add leading zeros to this so that it will look like a standard timing clock?

Use M and S :

$ date +"%H:%M:%S"
14:54:00

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM