Datetime Symfony2,条令,如何将日期时间设置为实体
我无法理解如何将datetime持久化到数据库。我有绳子Datetime Symfony2,条令,如何将日期时间设置为实体,datetime,symfony,doctrine,Datetime,Symfony,Doctrine,我无法理解如何将datetime持久化到数据库。我有绳子 (string) $oXml->currentTime 实际上,它不是一个字符串,但我们将其转换,所以如何将其添加到实体中而不会出错 Fatal error: Call to a member function format() on a non-object in... 现行代码 $currentTime = \DateTime::createFromFormat('Y-m-d H:m:s', (str
(string) $oXml->currentTime
实际上,它不是一个字符串,但我们将其转换,所以如何将其添加到实体中而不会出错
Fatal error: Call to a member function format() on a non-object in...
现行代码
$currentTime = \DateTime::createFromFormat('Y-m-d H:m:s', (string) $oXml->currentTime);
$cachedUntil = \DateTime::createFromFormat('Y-m-d H:m:s', (string) $oXml->cachedUntil);
$oApiKeyInfo
->setCurrentTime($currentTime)
->setCachedUntil($cachedUntil)
不工作:(您需要传递一个DateTime对象。使用新语句创建它,您可以指定与第一个构造函数参数一起使用的时间
$currentTime = new \DateTime((string) $oXml->currentTime);
$cachedUntil = new \DateTime((string) $oXml->cachedUntil);
$oApiKeyInfo->setCurrentTime($currentTime)
->setCachedUntil($cachedUntil);
如果需要指定时区,可以使用DateTimeZone类并将其作为第二个参数传递给DateTime构造函数。需要传递一个DateTime对象。使用新语句创建它,可以指定第一个构造函数参数使用的时间
$currentTime = new \DateTime((string) $oXml->currentTime);
$cachedUntil = new \DateTime((string) $oXml->cachedUntil);
$oApiKeyInfo->setCurrentTime($currentTime)
->setCachedUntil($cachedUntil);
如果需要指定时区,可以使用DateTimeZone类并将其作为第二个参数传递给DateTime构造函数。thnx解决方案位于“设置时区”thnx解决方案位于“设置时区”