在PHP< 5.3 [英] Creating DateTime from timestamp in PHP < 5.3

查看:158
本文介绍了在PHP< 5.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在小于< 5.3?

How do you create a DateTime from timestamp in versions less than < 5.3?

在5.3中将是:

$date = DateTime::createFromFormat('U', $timeStamp);

DateTime构造函数需要一个字符串,但这对我来说无效

The DateTime constructor wants a string, but this didn't work for me

$date = new DateTime("@$timeStamp");


推荐答案

假设你想要日期和时间,日期如上一个答案:

Assuming you want the date and the time and not just the date as in the previous answer:

$dtStr = date("c", $timeStamp);
$date = new DateTime($dtStr);

似乎很傻,不得不这样做。

Seems pretty silly to have to do that though.

这篇关于在PHP&lt; 5.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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