我的代码在那里:
如何显示上次登录时间(年、月、周、日、时间、秒).. 我试过但输出错误
上次登录时间:2012-05-11 10:16:51 当前时间:2012-05-11 10:35:51
$diff_seconds = strtotime($current_time) - strtotime($lastLoginTime);
这是正确的$diff_seconds -1336724211
我的代码在那里:
如何显示上次登录时间(年、月、周、日、时间、秒).. 我试过但输出错误
上次登录时间:2012-05-11 10:16:51 当前时间:2012-05-11 10:35:51
$diff_seconds = strtotime($current_time) - strtotime($lastLoginTime);
这是正确的$diff_seconds -1336724211
The following code gives me 1140
:
<?php echo strtotime('2012-05-11 10:35:51') - strtotime('2012-05-11 10:16:51'); ?>
There probably is an error elsewhere in your code that you're not showing us.
我无法重现那个。我做了
$time1 = '2012-05-11 10:16:51';
$time2 = '2012-05-11 10:35:51';
echo strtotime($time1) - strtotime($time2);
echo '<br>';
echo strtotime($time2) - strtotime($time1);
我得到了
-1140
1140
看起来合法。请出示您的代码。也许你没有字符串,它用你的年份数字做了一些奇怪的计算?
您想试试date_diff (PHP 5 >= 5.3.0) 作为选项吗?
http://php.net/manual/en/datetime.diff.php
<?php
$datetime1 = date_create('2012-05-11 10:16:51');
$datetime2 = date_create('2012-05-11 10:35:51');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%s seconds');
?>