search
Homephp教程php手册一个php日期函数,显示为n小时前发表

比如把: “2009-02-14 18:50 发表”<br>转成:“一个小时前发表”<br>

<?php <br/>function format_date($date)<br>{<br>    $limit = time() - $date;<br>    if($limit     {<br>        return $limit . '秒钟之前';<br>    }<br>    if($limit >= 60 && $limit     {<br>        return floor($limit/60) . '分钟之前';<br>    }<br>    if($limit >= 3600 && $limit     {<br>        return floor($limit/3600) . '小时之前';<br>    }<br>    if($limit >= 86400)<br>    {<br>        return date('Y-m-d H:i:s', $date);<br>    }<br>}<br>$time = 1234613275;<br>echo format_date($time);<br>?>



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools