Why can't I access DateTime->date in PHP's DateTime class?

前端 未结 5 1672
醉梦人生
醉梦人生 2020-11-22 06:44

Using the DateTime class, if I try to run the following code:

$mydate = new DateTime();
echo $mydate->date;

I\'ll get back

5条回答
  •  离开以前
    2020-11-22 07:09

    The date property of DateTime is protected.

    You can display the date with format function.

    format("Y-m-d H:i:s"));
    } catch (Exception $e) {
    }
    

    Or you can convert to array:

提交回复
热议问题