php中时间轴开发,即显示为“刚刚”、“5分钟前”、“昨天10:23"
//时间转换函数
function tranTime($time) {
$rtime = date("m-d H:i",$time);
$htime = date("H:i",$time);
$time = time() - $time;
if ($time
$str = '刚刚';
}
elseif ($time
$min = floor($time/60);
$str = $min.'分钟前';
}
elseif ($time
$h = floor($time/(60*60));
$str = $h.'小时前'.$htime;
}
elseif ($time
$d = floor($time/(60*60*24));
if($d==1)
$str = '昨天'.$rtime;
else
$str = '前天'.$rtime;
}
else {
$str = $rtime;
}
return $str;
}
函数tranTime()中的参数$time必须为Unix时间戳,如果不是请先用strtotime()将其转换成Unix时间戳。
调用函数,直接输出:
$times="1286861696 ";
echo tranTime($times);
作者:aolinks 's Blog

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment