开发者

PHP function that will turn a time stamp in the format yyyy-mm-dd hh:mm:ss into how old the time stamp is

Basically, I have a time stamp that looks like 2010-12-15 16:14:06. If the time stamp is seconds old I want it transform it into "N Seconds Old." If the time 开发者_JAVA百科stamp is minutes old, I want it to transform it into "N Minutes Old." etc. Is there any built in PHP functions that will do this?


if you're running 5.3 you can use DateTime::diff to do it. It returns a DateInterval object which contains the info you'll want.


As mentioned by others, you need to have some "starting point" to measure against. There are a number of ways to turn a time stamp such as 2010-12-15 16:14:06 into a PHP timestamp (seconds since 1970-01-01 00:00:00). If that's your "starting point", simply subtract it from the current time or whatever to get the difference in seconds. If less than a certain amount (say, 60), give that as "N seconds ago". If greater, divide by 60 to get minutes ago, or 3600 to get hours ago, etc.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜