php输出指定时间以前时间格式的方法,php时间格式
本文实例讲述了php输出指定时间以前时间格式的方法。分享给大家供大家参考。具体分析如下:
比如说你需要在php中输出3天前,20分钟以前,可以参考下面的代码
function ago($time) { $time = strtotime($time); $delta = time() - $time; if ($delta < 60) { return 'less than a minute ago.'; } else if ($delta < 120) { return 'about a minute ago.'; } else if ($delta < (45 * 60)) { return floor($delta / 60) . ' minutes ago.'; } else if ($delta < (90 * 60)) { return 'about an hour ago.'; } else if ($delta < (24 * 60 * 60)) { return 'about ' . floor($delta / 3600) . ' hour(s) ago.'; } else if ($delta < (48 * 60 * 60)) { return '1 day ago.'; } else { return floor($delta / 86400) . ' days ago.'; } }
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor