gpt4 book ai didi

php - 从 PHP < 5.3 中的时间戳创建 DateTime

转载 作者:IT老高 更新时间:2023-10-28 12:05:26 26 4
gpt4 key购买 nike

在低于 < 5.3 的版本中,如何根据时间戳创建 DateTime?

在 5.3 中会是:

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

DateTime 构造函数需要一个字符串,但这对我不起作用

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

最佳答案

PHP 5 >= 5.3.0

$date = new DateTime();
$date->setTimestamp($timeStamp);

编辑:setTimestamp

添加了正确的 PHP 版本

关于php - 从 PHP < 5.3 中的时间戳创建 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4329872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com