简体   繁体   中英

strange (?) behaviour with PHP DateTime object

I am trying to run the following

$d = "2015-Mar-22";
$dsd = DateTime::createFromFormat('Y-M-d H:i:s', $d . " 00:00:00");
$ds = strtotime($dsd->date);

and get

PHP Notice:  Undefined property: DateTime::$date in php shell code on line 1

However, if I call var_dump($dsd) before converting to a unix timestamp I get the correct answer:

echo strtotime($dsd->date);

1427007600

Am I missing something here?

You're attempting to use an undocumented property that is only ever made available due to a side effect.

->date being available is actually a side-effect of support for var_dump()


If you just want a timestamp use $dsd->getTimestamp() instead of strtotime($dsd->date) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM