Convert a time span in seconds to formatted time in shell

后端 未结 7 1965
鱼传尺愫
鱼传尺愫 2020-12-28 13:25

I have a variable of $i which is seconds in a shell script, and I am trying to convert it to 24 HOUR HH:MM:SS. Is this possible in shell?

7条回答
  •  温柔的废话
    2020-12-28 14:08

    Another approach: arithmetic

    i=6789
    ((sec=i%60, i/=60, min=i%60, hrs=i/60))
    timestamp=$(printf "%d:%02d:%02d" $hrs $min $sec)
    echo $timestamp
    

    produces 1:53:09

提交回复
热议问题