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微博发布时间, 感谢原作者分享。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号