Not yet rated

Problem

You have a date and time in Epoch seconds that you would like to convert to a date/time object.

Solution

Use dateAdd() to add the Epoch seconds to the Epoch date.

Detailed explanation

ColdFusion does not natively deal with dates based on the Epoch. However, as a developer, you may be faced with situations where you are provided with a date/time value stored in Epoch seconds. If this is the case, you can easily convert the value to a ColdFusion date/time object using the dateAdd() function.

<cfset e=1041397199>
 
<cfoutput>
#DateAdd("s",e,DateConvert("utc2Local", "January 1 1970 00:00"))#
</cfoutput>

In this example, the Epoch is first converted to local time using the DateConvert() function. Next, the number of Epoch
seconds we have are added to the converted Epoch time using dateAdd(). The output looks like this:

{ts '2002-12-31 23:59:59'}

Using the dateConvert() function is only necessary if you want to convert Epoch seconds to local time. You can leave it out if you simply want Epoch seconds converted to a date/time object in UTC.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes