比较 Coldfusion 和 PHP 时间戳(以毫秒为单位)
我正在使用自定义函数在 CF8 中创建时间戳。然后它通过查询字符串传递到 PHP 并再次与当前时间戳进行比较(使用 time())。由于 CF8 没有内置的 DateDiff() 毫秒选项,因此我在返回值(以秒为单位)的末尾附加了 3 个零。
但是,当我将其与 PHP 时间戳进行比较时,差异应该以秒为单位,但我得出了几个小时的差异。
<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
为了方便讨论,CF 时间戳为 1323344375000。与 PHP 的时间戳值为 1323362710000 相比,差异为 18,555,000 毫秒(超过 300 分钟)。实际过去的时间可能是2秒。
$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
我的转换失败在哪里?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 GMT 偏移的上下文中,您没有考虑服务器的本地时间。
将 getEpochTime() 修改为:
来源:GetEpochTimeFromLocal() (Rob-Brooks Bilson)
You're not taking the server's local time into consideration, within the context of the GMT offset.
Modify your getEpochTime() to:
Source: GetEpochTimeFromLocal() (Rob-Brooks Bilson)