CFLib.org – Common Function Library Project

convertSecondsToTimeString(timeInSeconds)

Last updated April 15, 2015

author

Simon Bingham

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 &quot;4d 12h 30m&quot; 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");
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson