换个方式显示日志发表时间和回复时间

function time_since($older_date, $newer_date = false)
	{
	// array of time period chunks
	$chunks = array(
	array(60 * 60 * 24 * 365 , 'year'),
	array(60 * 60 * 24 * 30 , 'month'),
	array(60 * 60 * 24 * 7, 'week'),
	array(60 * 60 * 24 , 'day'),
	array(60 * 60 , 'hour'),
	array(60 , 'minute'),
	);

	// $newer_date will equal false if we want to know the time elapsed between a date and the current time
	// $newer_date will have a value if we want to work out time elapsed between two known dates
	$newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date;

	// difference in seconds
	$since = $newer_date - $older_date;

	// we only want to output two chunks of time here, eg:
	// x years, xx months
	// x days, xx hours
	// so there's only two bits of calculation below:

	// step one: the first chunk
	for ($i = 0, $j = count($chunks); $i < $j; $i++)
		{
		$seconds = $chunks[$i][0];
		$name = $chunks[$i][1];

		// finding the biggest chunk (if the chunk fits, break)
		if (($count = floor($since / $seconds)) != 0)
			{
			break;
			}
		}

	// set output var
	$output = ($count == 1) ? '1 '.$name : "$count {$name}s";

	// step two: the second chunk
	if ($i + 1 < $j)
		{
		$seconds2 = $chunks[$i + 1][0];
		$name2 = $chunks[$i + 1][1];

		if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0)
			{
			// add to output var
			$output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
			}
		}

	return $output;
	}
<?php if (function_exists('time_since')) {
echo time_since(abs(strtotime($post->post_date_gmt . "GMT")), time()) . " ago";
} else {
the_time('F jS, Y');
} ?>
<?php if (function_exists(‘time_since’)) {
echo time_since(abs(strtotime($comment->comment_date_gmt . “ GMT”)), time()) . “ ago”;
} else {
the_time(‘F jS, Y’);
} ?>

via:http://www.happyet.org/357.html

-------------------------------------------------------------------------------------------

function time_ago( $type = 'post' ) {
	$d = 'comment' == $type ? 'get_comment_time' : 'get_post_time';
	return human_time_diff($d('U'), current_time('timestamp')) . &quot; &quot; . __('ago');
}
&lt;?php echo time_ago(); ?&gt;

发表评论

电子邮件地址不会被公开。

 smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

无觅相关文章插件,快速提升流量