Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

seconds conversion

Community Beginner ,
Apr 16, 2008 Apr 16, 2008
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,,,
TOPICS
Getting started
331
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2008 Apr 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 17, 2008 Apr 17, 2008
LATEST
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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources