Skip to content

Instantly share code, notes, and snippets.

@randomweapon
Created May 8, 2012 23:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save randomweapon/2640492 to your computer and use it in GitHub Desktop.
Save randomweapon/2640492 to your computer and use it in GitHub Desktop.
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