您也可以尝试time_since()
功能:
function time_since($older_date, $newer_date = false){
$chunks = array(
\'year\' => 60 * 60 * 24 * 365,
\'month\' => 60 * 60 * 24 * 30,
\'week\' => 60 * 60 * 24 * 7,
\'day\' => 60 * 60 * 24,
\'hour\' => 60 * 60,
\'minute\' => 60,
\'second\' => 1
);
$newer_date = ($newer_date == false) ? (time()+(60*60*get_option("gmt_offset"))) : $newer_date;
$since = $newer_date - $older_date;
foreach ($chunks as $key => $seconds)
if (($count = floor($since / $seconds)) != 0) break;
$messages = array(
\'year\' => _n(\'%s year ago\', \'%s years ago\', $count),
\'month\' => _n(\'%s month ago\', \'%s months ago\', $count),
\'week\' => _n(\'%s week ago\', \'%s weeks ago\', $count),
\'day\' => _n(\'%s day ago\', \'%s days ago\', $count),
\'hour\' => _n(\'%s hour ago\', \'%s hours ago\', $count),
\'minute\' => _n(\'%s minute ago\', \'%s minutes ago\', $count),
\'second\' => _n(\'%s second ago\', \'%s seconds ago\', $count),
);
return sprintf($messages[$key],$count);
}
可以这样称呼它:
echo time_since(abs(strtotime($post->post_date." GMT"));
我想
this 是代码的原始源代码