php时间2小时以前,PHP版实现友好的时间显示方式(例如:2小时前)

/*

* Data time functions.

// * 模块

*/

defined(‘TSKY’) || die(‘Permission Denied!’);

function fmtMonth($month){

return date(‘F, Y’,day2time($month.’01’));

}

//

function fmt_month($ts) {

return strftime(“%b,%Y”,$ts);

}

// 03:02

function shartTime($ts) {

return strftime(“%H:%M”,$ts);

}

// 03:02:01

function longTime($ts) {

return strftime(“%T”,$ts);

}

//4月18日

function shortDate($ts) {

return date(“n月d日”,$ts);

}

//2006年4月18日

function longDate($ts) {

return date(“Y年n月d日”,$ts);

}

function dateTime($ts) {

return date(“Y年n月d日 H:i:s”,$ts);

}

function fullDateTime($ts) {

return date(“Y年n月d日 “,$ts).week($ts);

}

function week($ts) {

global $lang;

return $lang[‘weekDay’][date(‘w’,$ts)];

}

function relatively_date($date) {

if (!preg_match(‘/^d+$/’, $date)) $date = strtotime(trim($date));

$sec = time() – $date;

switch(true){

case $sec < 3600:

return round($sec/60). ‘ 分钟前’;

case $sec < 86400:

return round($sec/3600). ‘ 小时前’;

case $sec < (86400 * 7):

return round($sec/86400). ‘ 天前’;//days ago

case $sec < (86400 * 7 * 4):

return round($sec/(86400*7)). ‘ 周前’; //weeks ago

default:

return longDate($date);

}

}

function nextMonth($month/*200512->200601*/){

return date(‘Ym’,strtotime(‘+1 month’,strtotime($month.’01’)));

}

function prevMonth($month/*200512->200511*/){

return date(‘Ym’,strtotime(‘-1 month’,strtotime($month.’01’)));

}

function prevDay($day/*20050826*/){

$day = substr($day,0,8);

return date(‘Ymd’,strtotime(‘-1 day’,strtotime($day)));

}

function nextDay($day/*20050826*/){

$day = substr($day,0,8);

return date(‘Ymd’,strtotime(‘+1 day’,strtotime($day)));

}

function nextExistsDay($day/*20050109*/){

$day = nextDay($day);

while(!hasTopic($day) && $day < TODAY){

$day = nextDay($day);

}

return hasTopic($day) ? $day : false;

}

function prevExistsDay($day/*20050109*/){

global $cfg;

$day = prevDay($day);

while(!hasTopic($day) && (int)$day > $cfg->origDate){

$day = prevDay($day);

}

return hasTopic($day) ? $day : false;

}

function prev_day($day){$day = substr($day,0,8);return date(‘Ymd’,strtotime(‘-1 day’,strtotime($day)));}

function long_date($ts){return date(“Y年n月d日”,$ts);}

function day2time($day){return @strtotime($day);}

/*

echo “

";

echo strftime(“a%an”);// a 星期二

echo strftime(“A%An”);// A 星期二

echo strftime(“b%bn”);// b 四月

echo strftime(“B%Bn”);// B 四月

echo strftime(“c%cn”);// c 2006-4-18 3:48:11

echo strftime(“C%Cn”);// C

echo strftime(“d%dn”);// d 18

echo strftime(“D%Dn”);// D

echo strftime(“e%en”);// e

echo strftime(“g%gn”);// g

echo strftime(“G%Gn”);// G

echo strftime(“h%hn”);// h

echo strftime(“H%Hn”);// H 03

echo strftime(“I%In”);// I 03

echo strftime(“j%jn”);// j 108

echo strftime(“m%mn”);// m 04

echo strftime(“M%Mn”);// M 48

echo strftime(“n%nn”);// n

echo strftime(“p%pn”);// p 上午

echo strftime(“r%rn”);// r

echo strftime(“R%Rn”);// R

echo strftime(“S%Sn”);// S 11

echo strftime(“t%tn”);// t

echo strftime(“T%Tn”);// T

echo strftime(“u%un”);// u

echo strftime(“U%Un”);// U 16

echo strftime(“V%Vn”);// V

echo strftime(“W%Wn”);// W 16

echo strftime(“w%wn”);// w 2

echo strftime(“x%xn”);// x 2006-4-18

echo strftime(“X%Xn”);// X 3:48:11

echo strftime(“y%yn”);// y 06

echo strftime(“Y%Yn”);// Y 2006

echo strftime(“Z%Zn”);// Z 中国标准时间

echo strftime(“%%%n”);// %

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值