下面实例是告诉我们在论坛有看到关于多少秒钟前发了帖子等这些功能,
分析
实际时间 PHP
1秒 2“秒”
______________________
30秒==60
5分钟==60*10 //这里我觉得应该是五分钟,而不是一分钟,个人觉得 一分钟的话应该是 60*2
10分钟==60*20
30分钟==60*60
1小时==60*60*2
2.5小时==60*60*5
原理
用当前时间time(),减去你信息录入时的新增时间,(注意是时间戳),然后得出的差数,就是秒数,再根据自己的需要来转换啊。例如你想转换成分钟,就除以60。
实例
代码如下 | 复制代码 |
/** $unitArr = array('年' =>'year', '个月'=>'month', '周'=>'week', '天'=>'day', foreach ( $unitArr as $cn => $u ) return $elapse; $past = 2052345678; // Some timestamp in the past echo '发表于' . time2Units($diff) . '前'; |
这是一个刚入门的同学写的
代码如下 | 复制代码 |
$regist1 = "05/12/2006"; list($month1,$day1,$year1) = explode("/",$regist1); $regist1 = mktime(0,0,0,$month1,$day1,$year1); $time_difference = $regist2-$regist1; echo ("时间差:"); |
好了喜欢就自己选择用吧。
本文地址:
转载随意,但请附上文章地址:-)

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

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.