DateTime () is not working properly

There is a situation in PHP Symfony2:

$myDate = new \DateTime();
var_dump($myDate);

Return:

class DateTime#17476 (3) {
  public $date =>
  string(19) "2014-05-26 14:44:53"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(13) "Europe/Warsaw"
}

But:

$myDate = new \DateTime();
var_dump($myDate->date);

Returns ... NULL

What am I doing wrong?

+4
source share
1 answer

Mostly because you are using it incorrectly, you need to use DateTime methods correctly.

In this case, use . Read the manual for more information . Consider this example: ->format()

$myDate = new \DateTime();
// yyyy-mm-dd hh:mm:ss
echo $myDate->format('Y-m-d H:i:s'); // output: 2014-05-26 20:54:21
// timestamp
echo $myDate->getTimestamp(); // output: 1401108861
+6
source

Source: https://habr.com/ru/post/1542038/


All Articles