Php date_timestamp 上的警告消息

Php warning message on date_timestamp

您好,我正在尝试从 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 

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

谢谢

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

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