CFLib.org – Common Function Library Project

getTimeFromSeconds(seconds)

Last updated June 19, 2013

author

Seth Duffey

Version: 2 | Requires: CF5 | Library: DateLib

Description:
Calculates time from seconds after midnight. The date part of a time variable is set to December 30, 1899

Return Values:
Returns a date/time object.

Example:

<CFSET s=10000>

<cfoutput>
Given s=#s#<BR>
#TimeFormat(GetTimeFromSeconds(s), 'HH:mm:ss')#
</cfoutput>

Parameters:

Name Description Required
seconds Number of seconds from midnight used to calculate the time. Yes

Full UDF Source:

/**
 * Calculates time from seconds after midnight.
 * Minor modifications by Rob Brooks-Bilson (rbils@amkor.com).
 * v2 by Raymond Camden to support seconds over one day
 * 
 * @param seconds 	 Number of seconds from midnight used to calculate the time. (Required)
 * @return Returns a date/time object. 
 * @author Seth Duffey (sduffey@ci.davis.ca.us) 
 * @version 2, June 19, 2013 
 */
function getTimeFromSeconds(seconds) {

	var timehr = "";
	var timemin = "";
	var timesec = "";
	
	//roll days
	if(seconds gt 86400) seconds = seconds-((seconds \ 86400) * 86400);

	TimeHr = (((seconds\3600)-1) Mod 24)+1; /* find hour */
	TimeMin = seconds\60-(seconds\3600)*60; /* Find minutes */
	TimeSec = seconds-(TimeHr * 3600) - (TimeMin*60); /* find seconds */
	return createTime(TimeHr,TimeMin,TimeSec); /* Create time (no date) */

}
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