convertSecondsToTimeString(timeInSeconds)
Last updated April 15, 2015
Version: 2 | Requires: CF9 | Library: DateLib
Description:
Takes a time in seconds argument and converts to a time string in "4d 12h 30m" format.
Return Values:
Returns a string formatting the passed-in seconds value in days, hours and minutes
Example:
<cfoutput>
<h2>Test Seconds</h2>
<cfloop index="variables.seconds" from="0" to="60" step="15">
#convertSecondsToTimeString(variables.seconds)#<br>
</cfloop>
<h2>Test Minutes</h2>
<cfloop index="variables.seconds" from="0" to="3600" step="60">
#convertSecondsToTimeString(variables.seconds)#<br>
</cfloop>
<h2>Test Hours</h2>
<cfloop index="variables.seconds" from="0" to="86399" step="3600">
#convertSecondsToTimeString(variables.seconds)#<br>
</cfloop>
<h2>Test All</h2>
<cfloop index="variables.seconds" from="39600" to="40200" step="1">
#convertSecondsToTimeString(variables.seconds)#<br>
</cfloop>
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
timeInSeconds | Time in seconds | Yes |
Full UDF Source:
/**
* Takes a time in seconds argument and converts to a time string in "4d 12h 30m" format.
* v0.9 by Simon Bingham
* v1.0 by Adam Cameron. Tweaking small bug if a float is passed-in rather than an integer.
*
* @param timeInSeconds Time in seconds (Required)
* @return Returns a string formatting the passed-in seconds value in days, hours and minutes
* @author Simon Bingham (me@simonbingham.me.uk)
* @version 2.0, April 15, 2015
*/
function convertSecondsToTimeString(seconds) {
local.hours = arguments.seconds \ 3600;
local.minutes = (arguments.seconds \ 60) mod 60;
local.seconds = (arguments.seconds) mod 60;
return numberformat(local.hours, "0") & ":" & numberformat(local.minutes, "00") & ":" & numberformat(local.seconds, "00");
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016