gpt4 book ai didi

php - Typo3 DateTime setter 问题

转载 作者:行者123 更新时间:2023-12-04 00:33:46 27 4
gpt4 key购买 nike

我的约会模型有一个值 $created,它的数据类型是 DateTime。但出于某种原因,我无法设置 $created 值。

我尝试了很多格式,但就是不会设置值。当函数到达 setCreated() 时它会卡住。 (所有其他值(整数、字符串)都设置成功,只是这个\DateTime var 没有)

$appointment->setCreated('1439878630');  //Doesn't work
$appointment->setCreated(1439878630); //Doesn't work
$appointment->setCreated('1990-11-14T15:32:12+00:00'); //Doesn't work
$appointment->setCreated('1990-11-14 15:32:12'); //Doesn't work

我的二传手方法:

 /**
* Sets the created
*
* @param \DateTime $created
* @return void
*/

public function setCreated(\DateTime $created) {
$this->created = $created;
}

如何使用时间戳(或任何其他日期格式)设置 $created 值??任何帮助表示赞赏!谢谢你的努力。

最佳答案

setCreated 方法需要一个 DateTime 对象,而不是字符串。所以给它一个:

$appointment->setCreated(new \DateTime('<insert your date string here>'));

可以在 PHP documentation 中找到接受的时间字符串列表。 .

关于php - Typo3 DateTime setter 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092933/

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