Convert seconds to compound duration: Difference between revisions
Content added Content deleted
(Added Befunge example.) |
Alpha bravo (talk | contribs) (Added AutoHotkey) |
||
Line 126: | Line 126: | ||
6001230 SECONDS = 9 WK, 6 D, 11 HR, 30 SEC |
6001230 SECONDS = 9 WK, 6 D, 11 HR, 30 SEC |
||
600000000 SECONDS = 992 WK, 10 HR, 40 MIN</pre> |
600000000 SECONDS = 992 WK, 10 HR, 40 MIN</pre> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>duration(n){ |
|||
sec:=1, min:=60*sec, hr:=60*min, day:=24*hr, wk:=7*day |
|||
w :=n//wk , n:=Mod(n,wk) |
|||
d :=n//day , n:=Mod(n,day) |
|||
h :=n//hr , n:=Mod(n,hr) |
|||
m :=n//min , n:=Mod(n,min) |
|||
s :=n |
|||
return trim((w?w " wk, ":"") (d?d " d, ":"") (h?h " hr, ":"") (m?m " min, ":"") (s?s " sec":""),", ") |
|||
}</lang> |
|||
Examples:<lang AutoHotkey>data= |
|||
( |
|||
7259 |
|||
86400 |
|||
6000000 |
|||
) |
|||
loop, parse, data, `n, `r |
|||
res .= A_LoopField "`t: " duration(A_LoopField) "`n" |
|||
MsgBox % res |
|||
return</lang> |
|||
Outputs:<pre>7259 : 2 hr, 59 sec |
|||
86400 : 1 d |
|||
6000000 : 9 wk, 6 d, 10 hr, 40 min</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |