Convert Milliseconds to Hours : Minutes : Seconds in Coldfusion?

coldfusion

Solution

@craigster's answer is useful if you want just the number of hours or the minutes or the seconds represented by the milliseconds.

If you want all three, you need to do a bit more arithmetic.

For instance, 23 hrs 59 mins 55 seconds:

  (23 * 60 * 60 * 1000)
+ (59 * 60 * 1000)
+ (55 * 1000)
= 86395000 milliseconds

To convert 86395000 back into HH:MM:SS you could do:

<cfscript>
hours = int(duration_in_milliseconds \ (60 * 60 * 1000));
mins = (duration_in_milliseconds \ (60 * 1000)) mod 60;
secs = (duration_in_milliseconds \ 1000) mod 60;
</cfscript>

<cfoutput>#hours# #mins# #secs#</cfoutput>

Problem

I am getting a a field called duration_in_milliseconds from an API, is there a function or a way to convert that to hours:minutes:seconds somehow? I've looked and can't find any solutions. Thanks for any help?

Original source