5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

秒を日:時:分:秒に変換するシェルスクリプト

Posted at
#!/bin/sh
if [ $# -eq 2 ]; then
	start_time=$1
	end_time=$2
elif [ $# -eq 1 ]; then
	start_time=0
	end_time=$1
fi

diff=$((end_time - start_time))
let day="$diff / 86400"
let diff="$diff % 86400"
let hour="$diff / 3600"
let diff="$diff % 3600"
let minitue="$diff / 60"
let second="$diff % 60"
echo "${day}d:${hour}h:${minitue}m:${second}s"

引数が1個の場合は、秒を日:時:分:秒に変換。
引数が2個の場合は、経過時間を日:時:分:秒に変換。

5
3
0

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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?