Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
create linux date time in coldfusion as well as convert epoch time back to a coldfusion date.
<cfcomponent>
<!---
Function Name : linuxDateTime()
Author : Ryan Spencer
Created : 26/09/2008
General Notes : Returns the date from a Epoch Time format of seconds
since UTC January 1, 1970, 00:00:00 (Epoch time).
Function in :
- date as seconds int
Function return :
- coldfusion date datetime
--->
<cffunction name="convertEpochTime">
<cfargument name="dateSeconds" default="">
<cfscript>
// set the base time from when epoch time starts
startDate = createdatetime( '1970','01','01','00','00','00' );
if ( NOT isnumeric( arguments.dateSeconds ) )
return '';
// return the date
// this adds the seconds to the startDate and the converts it to to a local time from UTC format
return dateConvert( "utc2Local", dateadd( 's', arguments.dateSeconds, startDate ) );
</cfscript>
</cffunction>
<cffunction name="epochTime">
<cfscript>
// set the base time from when epoch time starts
startDate = createdatetime( '1970','01','01','00','00','00' );
datetimeNow = dateConvert( "local2Utc", now() );
return datediff( 's', startdate, datetimeNow );
</cfscript>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.