剩余时间是指一篇文章什么时候发布到现在有几分钟或几天了,这个在很多博客论坛都以看到文章1天以前发布的,下面我介绍两实例
把两个日期格式的字符串转化成unix时间戳,然后相减获得时间戳差。最后判断剩余时间,生成类似(2小时30分钟20秒前发布)这样的时间格式
| 代码如下 | 复制代码 |
|
public function gettime($time_s,$time_n){ |
|
首先判断想减之后的值是否大于一天的秒数86400秒,如果大于的话就返回原来的数据库查询出来的时间
然后判断是否在1小时到一天之内,也就是3600秒-86400秒,如果是之内的话就返回X小时。得到结果后还需使用取余数的方法去除小时部分的时间,使用 %取余
然后判断是否在1分钟到一小时之内,也就是60秒-3600秒,如果是之内的话就返回X分钟。得到结果后还需使用取余数的方法去除分钟部分的时间,使用 %取余
最后判断是否在1分钟之内,也就是0秒-60秒,如果是之内的话就返回X分秒
注意:上面得出的结果都是使用.=连接的。这样最后才得到一个整体的时间。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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.





