PHP功能将以yyyy-mm-dd hh:mm:ss的格式转换为时间戳的时间戳 [英] PHP function that will turn a time stamp in the format yyyy-mm-dd hh:mm:ss into how old the time stamp is

查看:493
本文介绍了PHP功能将以yyyy-mm-dd hh:mm:ss的格式转换为时间戳的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个时间戳,看起来像 2010-12-15 16:14:06 。如果时间戳是秒,我希望它变成N秒旧。如果时间戳是几分钟,我想让它变成N分钟老。有没有内置的PHP函数会这样做?

解决方案

如果你运行5.3,你可以使用 DateTime :: diff 来做。它返回一个 DateInterval 对象,其中包含您想要的信息。 / p>

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 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.

这篇关于PHP功能将以yyyy-mm-dd hh:mm:ss的格式转换为时间戳的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆