This will convert a second into a more feasible number split up into parts of hrs/min/sec (or if you want also days and weeks and years)

Provided 5 configurations of this converter for your use:

* hms (hour minute second)
* dhms (day hour minute second)
* wdhms (week day hour minute second)
* ywdhms (year week day hour minute second)
* ydhms (year day hour minute second)

Note that the value on the left most can be anything from 0 to infinity (and in the negative range), but the numbers to the right will be rotated/moded accordingly (seconds will be rotated every 60, minutes every 60, hours every 24, weeks every 7, or days every 365 if using the last config there)

Each function provided below will be demonstrated via test variables
Notice there are many correct ways to output the results.

Citation/used this article as source for algorithm: http://stackoverflow.com/questions/12199631/convert-seconds-to-hours-minutes-seconds-in-bash

Here is the original method (from the above link):

Here are my methods:

hour:min:sec

day-hour:min:sec
week:day-hour:min:sec
year:week:day-hour:min:sec
year:day-hour:min:sec
AWK VERSION OF THE SAME SCRIPTS

Leave a Reply

Your email address will not be published. Required fields are marked *