Convert seconds to hours, minutes, seconds

前端 未结 13 1006
梦谈多话
梦谈多话 2020-12-02 14:08

How can I convert seconds to hours, minutes and seconds?

show_time() {
  ?????
}

show_time 36 # 00:00:36
show_time 1036 # 00:17:26
show_time 91925 # 25:32:0         


        
13条回答
  •  温柔的废话
    2020-12-02 14:37

    All above is for bash, disregarding there "#!/bin/sh" without any bashism will be:

    convertsecs() {
        h=`expr $1 / 3600`
        m=`expr $1  % 3600 / 60`
        s=`expr $1 % 60`
        printf "%02d:%02d:%02d\n" $h $m $s
    }
    

提交回复
热议问题