您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP实现类似Sina微博发布时间

2024/4/8 5:59:49发布12次查看
public static function timeformatter($time) { $dt_now=date('y-m-d h:i:s',time()); $days = dateutil::interval(d,$time,$dt_now); $hours = dateutil::interval(h,$time,$dt_now); $minutes = dateutil::interval(n,$time,$dt_now); $seconds = d
public static function timeformatter($time) { $dt_now=date('y-m-d h:i:s',time()); $days = dateutil::interval(d,$time,$dt_now); $hours = dateutil::interval(h,$time,$dt_now); $minutes = dateutil::interval(n,$time,$dt_now); $seconds = dateutil::interval(s,$time,$dt_now); if ($days == 0 && $hours == 0 && $minutes == 0) { return $seconds . 秒前; } else if ($days == 0 && $hours == 0) { return $minutes . 分钟前; } else if ($days == 0) { return 今天 . date(h:i, strtotime($time)); } else { return date(m月d日 h:i, time()); } } public static function interval($interval = d, $date1, $date2) { $timedifference = strtotime($date2) - strtotime($date1); $days = bcdiv($timedifference, 86400); if ($interval == 'd') { return $days; } $temp1 = $timedifference % (86400); $hours = bcdiv($temp1, 3600); if ($interval == 'h') { return $hours; } $temp2 = $temp1 % (3600); $minutes = bcdiv($temp2, 60); if ($interval == 'n') { return $minutes; } $seconds = $temp2 % 60; if ($interval == 's') { return $seconds; } }
原文地址:php实现类似sina微博发布时间, 感谢原作者分享。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product