user2378735
user2378735

Reputation: 1

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 (i.e. 1:7 instead of 01:07). How do I add leading zeros to this so that it will look like a standard timing clock?

Upvotes: 0

Views: 112

Answers (1)

user1907906
user1907906

Reputation:

Use M and S:

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

Upvotes: 1

Related Questions