如何在PHP中将unix时间戳转换为ISO8601时间戳? [英] How to convert a unix timestamp to an ISO8601 timestamp in PHP?

查看:170
本文介绍了如何在PHP中将unix时间戳转换为ISO8601时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从mysql中提取unix时间戳并将其转换为ISO8601时间戳.我需要它以便将日期格式设置为"30分钟前"的类Facebook(或类堆栈溢出:)格式,而不是显示确切的日期和时间.有人处理过吗?

I am trying to extract unix timestamp from mysql and convert it to ISO8601 timestamp. I need it in order to format date into facebook-like(or stack-overflow-like:) '30 minutes ago' instead of displaying the exact date and time. Has anyone dealt with it?

推荐答案

$timestamp = '1268932078';

$iso8601 = date('c', $timestamp);

但是,如果您不想自己动手,则有内置功能可以帮助您解决此问题,例如:

But there are built-in functions to help you with this if you don't want to roll your own, e.g.: DateTime::diff.

这篇关于如何在PHP中将unix时间戳转换为ISO8601时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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