首页 >后端开发 >php教程 >友好的显示时间 PHP端

友好的显示时间 PHP端

WBOY
WBOY原创
2016-07-28 08:26:171111浏览

<code><span>/**
     * 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前, 如果超过1年, 就直接显示具体时间
     *
     *<span> @param</span> int    $inputTimestamp UnixTimestamp
     *<span> @param</span> string $overflowTimeFormat 超过3天的时间显示格式
     *
     *<span> @return</span> string
     */</span><span>static</span><span>public</span><span><span>function</span><span>timeAgo</span><span>(<span>$inputTimestamp</span>,<span>$overflowTimeFormat</span> = <span>'Y/m/d H:i'</span>)</span>
    {</span><span>if</span> (<span>empty</span>(<span>$inputTimestamp</span>) || !is_numeric(<span>$inputTimestamp</span>) || !<span>$inputTimestamp</span>) {
            <span>return</span><span>''</span>;
        }
        <span>$d</span> = time() - <span>$inputTimestamp</span>;
        <span>if</span> (<span>$d</span> 0) {
            <span>return</span><span>''</span>;
        } <span>else</span> {
            <span>if</span> (<span>$d</span> 60) {
                <span>return</span><span>$d</span> . <span>'秒前'</span>;
            } <span>else</span> {
                <span>if</span> (<span>$d</span> 3600) {
                    <span>return</span> floor(<span>$d</span> / <span>60</span>) . <span>'分钟前'</span>;
                } <span>else</span> {
                    <span>if</span> (<span>$d</span> 86400) {
                        <span>return</span> floor(<span>$d</span> / <span>3600</span>) . <span>'小时前'</span>;
                    } <span>else</span> {
                        <span>if</span> (<span>$d</span> 259200) {<span>//3天内</span><span>return</span> floor(<span>$d</span> / <span>86400</span>) . <span>'天前'</span>;
                        } <span>else</span> {
                            <span>return</span> date(<span>$overflowTimeFormat</span>,<span>$inputTimestamp</span>);
                        }
                    }
                }
            }
        }
    }</code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了 友好的显示时间 PHP端,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn