简体   繁体   English

GeekTool(UNIX)计数器前导零

[英]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: 我正在尝试通过Mac(基于UNIX)上的GeekTool进行比赛的计时计数器,并具有以下几点:

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). 问题是,当分钟或秒小于10时,就没有前导零(即1:7而不是01:07)。 How do I add leading zeros to this so that it will look like a standard timing clock? 如何在此添加前导零,使其看起来像标准计时时钟?

Use M and S : 使用MS

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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