PHP格式化显示时间函数,用于微博、社交媒体等,类似豆瓣



/**
* 格式化显示时间函数
*
* 类似豆瓣(几秒前/几分前/今天3:50/昨天3:50/3-6)
*
* @param $timestamp 时间戳 必选参数,后面三个参数可选,为提高计算速度,建议直接赋值
* @param $now 当前时间戳
* @param $today 今天00:00时间戳
* @param $yesterday 昨天00:00时间戳
* @return string
*/
function timeshow($timestamp,$now=0,$today=0,$yesterday = 0){
if(! $timestamp){return '';}
if(! $now){$now = time();}
if(! $today){$today = strtotime("today");}
if(! $yesterday){$yesterday = $today-86400;}
$cha = $now-$timestamp;
if($cha<60){
return $cha."秒前";
}elseif($cha<60*60){
$min = floor($cha/60);
return $min."分钟前";
}elseif($timestamp>=$today){
return date("今天H:i",$timestamp);
}elseif($timestamp>=$yesterday){
return date("昨天H:i",$timestamp);
}else{
return date("m-d",$timestamp);
}
}


( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0001355192{main}( ).../index.php:0
20.0001355480require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.171610154000require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.172810225144include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.253010828344get_template_part( ).../single.php:5
60.253010828864locate_template( ).../general-template.php:167
70.253010828960load_template( ).../template.php:643
80.253010829344require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.257910814456cwppos_show_review( ).../content-single.php:29

9 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注