2

I'm creating a timestamp in CF8 using a custom function. It's then being passed via query string to PHP and compared, again, to the current timestamp (using time()). Since CF8 doesn't have a built-in millisecond option for DateDiff(), I appended 3 zeroes to the end of the returned value (which is in seconds).

But, when I compare it against the PHP timestamp, the difference should be in seconds, but I'm coming up with a multi-hour difference.

<cfscript>
function GetEpochTime() {
    datetime = Now();
    return DateDiff("s", "January 1 1970 00:00", datetime) & "000"; //zeroes padded for milliseconds
}
</cfscript>
<cfset foo = getepochtime() /> //Returns time stamp

For the sake of argument, the CF timestamp reads 1323344375000. When compared against PHP's stamp with a value of 1323362710000, the difference is 18,555,000 milliseconds (over 300 minutes). Real time that has passed is maybe 2 seconds.

$php_ts = time() * 1000; //PHP timestamp is in seconds, too
$cf_ts = $_GET['coldfusion_timestamp'];
echo $ts_difference = ($php_ts - $cf_ts) / (1000 * 60); //Difference in minutes

Where is my conversion failing?

justacoder
  • 2,684
  • 6
  • 47
  • 78
  • 1
    Are CF and PHP running on the same server, or different ones? 18,555 seconds is ~5.15 hours, so there's a 5 hour time zone in play, and a ~9 minute clock skew between the two systems. – Marc B Dec 08 '11 at 17:22
  • They are not, but both servers are in-house so their timestamps should not be this far apart. – justacoder Dec 08 '11 at 17:32

1 Answers1

2

You're not taking the server's local time into consideration, within the context of the GMT offset.

Modify your getEpochTime() to:

 return DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), datetime) & "000";

Source: GetEpochTimeFromLocal() (Rob-Brooks Bilson)

Shawn Holmes
  • 3,752
  • 22
  • 25