I am writing an application where I need to get the epoch time on the server side using ColdFusion 8 running on Windows Server 2008 and client side using javascript (testing in Google Chrome). The problem is that the epoch time generated by ColdFusion is one hour behind the one generated by javascript. I have verified that the date/time settings are correct both client side and server side.
This is how I am setting the time stamp with ColdFusion:
<cfset cfEpoch = DateDiff("s", "January 1 1970 00:00", DateConvert("Local2utc", now()))>
And this is how I'm setting it with javascript:
var jsEpoch = Math.round(new Date().getTime()/1000.0);
The javascript epoch matches the one on this website (http://www.epochconverter.com/) which makes sense because they're using the same method I'm using. The ColdFusion epoch is one hour behind. Here's what I've run to try to sort this out:
<cfset localDate = now()>
<cfset utcDate = DateConvert("Local2utc", localDate)>
<cfset epoch = DateDiff("s", "January 1 1970 00:00", utcDate)>
<cfoutput>
Local Date: #localDate# <br>
UTC Date: #utcDate# <br>
Epoch: #epoch#
</cfoutput>
That code outputs:
Local Date: {ts '2013-04-30 17:44:56'}
UTC Date: {ts '2013-04-30 21:44:56'}
Epoch: 1367354696
So I'm at a loss. Both the local date and UTC date values are correct. It appears that the only explanation is that the DateDiff() function isn't working properly, but I've tested it with other dates and it seems to work fine. I suppose I can just add 3600 to the epoch value it generates but I'd rather not do that without knowing why I'm getting an incorrect value in the first place. Does anyone see what I'm missing here?