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?
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Invoking Mirth Connect CLI with Powershell script
- Error building gcc 4.8.3 from source: libstdc++.so
If
$i
represents some date in second since the Epoch, you could display it withbut you seems to suppose that
$i
is an interval (e.g. some duration) not a date, and then I don't understand what you want.Continuing @Daren`s answer, just to be clear: If you want to use the conversion to your time zone, don't use the "u" switch, as in:
date -d @$i +%T
or in some casesdate -d @"$i" +%T
.The
-d
argument applies to date fromcoreutils
(Linux) only.In BSD/OS X, use
Another approach: arithmetic
produces
1:53:09
Here is my algo/script helpers on my site: http://ram.kossboss.com/seconds-to-split-time-convert/ I used this elogant algo from here: Convert seconds to hours, minutes, seconds
Example of my second to day, hour, minute, second converter:
I use C shell, like this: