我试图将经过的时间放在评论框中。
尝试使用下面的代码,但是它给了我 45 年的时间。
这是我的代码
$data = $row['created_on'];
$time = strtotime('$data');
<li>
<span class="author">
<?php echo $row['name']; ?>
</span>
<span class="time">
<?php echo ''.humanTiming($time).' ago'; ?>
</span><br/>
<div class="c_content">
<?php echo $row['comment']; ?>
</div>
<div class="clear"></div>
</li>
<?php } ?>
</ul>
<?php
function humanTiming ($time){
$time = time() - $time; // to get the time since that moment
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
}
}