date_timestamp上的Php警告消息

问题描述 投票:1回答:1

您好我正在尝试从wordpress插件中的DateTime对象获取时间戳。尽管我设法得到时间戳我收到了一个警告(PHP版本7.1.26)。这是我到目前为止所做的:

$x=$season->getStartDate();
//DateTime Object ( [date] => 2019-07-12 14:45:14.000000 [timezone_type] => 3 [timezone] => UTC )

$timestamp=date_timestamp_get($x); 
//1562942714
//Warning: date_timestamp_get() expects parameter 1 to be DateTimeInterface, null given 

如何消除警告(不禁用警告消息)

谢谢

wordpress datetime php-7.1
1个回答
0
投票

您已经有一个可以使用的对象。所以试试$season->getTimestamp();

https://secure.php.net/manual/de/datetime.gettimestamp.php

© www.soinside.com 2019 - 2024. All rights reserved.