Heim >Backend-Entwicklung >PHP-Tutorial >友好的显示时间 PHP端
<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教程有兴趣的朋友有所帮助。