php strtotime反向

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php strtotime反向脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP是否有一些函数timetostr将在今天/明天/下一个星期日/等输出.从给定的时间戳?所以timetostr(strtotime(x))= x
这可能对来这里的人有用.
/**
 * 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",["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);
    }
}

脚本宝典总结

以上是脚本宝典为你收集整理的php strtotime反向全部内容,希望文章能够帮你解决php strtotime反向所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。