Skip to main content
Known Participant
April 16, 2008
Question

seconds conversion

  • April 16, 2008
  • 2 replies
  • 351 views
Does anyone know of a way to convert seconds to hh:mm:ss format? I have a total seconds value of 120, for example, and I want a CF page to display it as 00:02:00. Thanks,,,
This topic has been closed for replies.

2 replies

12Robots
Participating Frequently
April 17, 2008
This solution will work up to 24 Hours. If you need to display times long than that, you will have to do some math.
You MUST use the capital H in the TimeFormat() function, of it will try to convert it to a 12-hour clock and you will get weird results.

<cfset second = 60 />
<cfset myTime = CreateTimeSpan(0, 0, 0, second)>
<cfoutput>
#Timeformat(myTime, 'H:mm:ss')#
</cfoutput>
Inspiring
April 16, 2008
The mod operator gives you the remainder when you divide one number into another. Numberformat enables you to format any number (hint, you'll need three of them).

Or, you can check cflib.org to see if a udf for this already exists.