LoginSignup
6

More than 5 years have passed since last update.

bashの計算式で、秒数をHH:MM:SSフォーマットに変換する

Last updated at Posted at 2015-06-01

ほぼこれ。

ただし、上記記事のコードだと$iを上書きしてしまうので、そこだけ直した。

%は余りを求める。/は余りを除いた商を求める。

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

総計を60*60で割った余りをさらに60で割ることで、分の位を求める。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6