-
-
Save ivanionut/1f1e0100a847e717f20535531d6030a7 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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