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
Here's a fun hacky way to do exactly what you are looking for =)
Explanation:
date
utility allows you to specify a time, from string, in seconds since 1970-01-01 00:00:00 UTC, and output it in whatever format you specify.-u
option is to display UTC time, so it doesn't factor in timezone offsets (since start time from 1970 is in UTC)date
-specific (Linux):-d
part tellsdate
to accept the time information from string instead of usingnow
@${i}
part is how you telldate
that$i
is in seconds+"%T"
is for formatting your output. From theman date
page:%T time; same as %H:%M:%S
. Since we only care about theHH:MM:SS
part, this fits!