在我的计算机和Linux服务器之间减去两个日期时的两个不同结果

时间:2014-03-08 13:29:01

标签: php date

我在计算机和hostgator服务器上使用相同的代码。这是代码:

<?php
$checkout = "2014/03/11";
$checkin = "2014/03/09";

$checkin = date('Y/m/d', strtotime($checkin));
$checkout = date('Y/m/d', strtotime($checkout));

echo $checkin."<br />";
echo $checkout."<br />";

$nights = (strtotime($checkout) - strtotime($checkin)) / (60 * 60 * 24);

echo $nights;
?>

但是我得到了不同的结果。在我的计算机上显示正确的答案,即“2”。但在我的服务器上显示“1.95833333333”。

谁能告诉我什么是错的?

更新

以下是上述代码的输出:

2014/03/09
2014/03/11
1.95833333333

1 个答案:

答案 0 :(得分:1)

在使用strtotime();

之前,您必须使用date_default_timezone_set($timezone)设置时区