我有这个代码来获取过去两个时间戳之间的区别,一个是NOW,我希望在秒和分钟,小时和天中有差异,但每次都得到错误的值。我需要知道我是否正在划分正确的价值观:
<?php
$timestamp = '2013-11-16 16:26:30';
$post_date = strtotime($timestamp);
//echo $post_date;echo '</br>';
date_default_timezone_set('Asia/Istanbul');
$now = new DateTime();
$now_date = $now->getTimestamp();
//echo $now_date;
$timediff = $now_date - $post_date;
echo floor($timediff/1000);echo' Seconds';
echo floor($timediff/60);echo' Minutes';
echo floor(($timediff/60)/60);echo' Hours';
echo floor(((($timediff/60)/60)/24));echo' Days';
?>
答案 0 :(得分:-1)
这对你有用。
$timestamp = '2013-11-17 00:00:00';
$post_date = strtotime($timestamp);
date_default_timezone_set('Asia/Istanbul');
$now = new DateTime();
$now_date = $now->getTimestamp();
//echo $now_date;
$timediff = $now_date - $post_date;
echo floor($timediff%60).' Seconds<br>';
echo floor($timediff/60 % 60).' Minutes<br>';
echo floor(($timediff/3600 % 24)).' Hours<br>';
echo floor(((($timediff/60)/60)/24)).' Days';