php反向机制,php strtotime反向

这可能对来这里的人有用.

/**

* Format a timestamp to display its age (5 days ago, in 3 days, etc.).

*

* @param int $timestamp

* @param int $now

* @return string

*/

function timetostr($timestamp, $now = null) {

$age = ($now ?: time()) - $timestamp;

$future = ($age < 0);

$age = abs($age);

$age = (int)($age / 60); // minutes ago

if ($age == 0) return $future ? "momentarily" : "just now";

$scales = [

["minute", "minutes", 60],

["hour", "hours", 24],

["day", "days", 7],

["week", "weeks", 4.348214286], // average with leap year every 4 years

["month", "months", 12],

["year", "years", 10],

["decade", "decades", 10],

["century", "centuries", 1000],

["millenium", "millenia", PHP_INT_MAX]

];

foreach ($scales as list($singular, $plural, $factor)) {

if ($age == 0)

return $future

? "in less than 1 $singular"

: "less than 1 $singular ago";

if ($age == 1)

return $future

? "in 1 $singular"

: "1 $singular ago";

if ($age < $factor)

return $future

? "in $age $plural"

: "$age $plural ago";

$age = (int)($age / $factor);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值