Why does DateTime::createFromFormat() fails and returns a boolean in my second example?

后端 未结 3 1610
醉话见心
醉话见心 2021-02-18 14:13

When I run this the first one is correctly created into a date. The second one fails, returning a boolean and so I cannot format. Is the time out of range?

3条回答
  •  清歌不尽
    2021-02-18 14:39

    In addition to the other answers, for standard formats understood by DateTime you don't need to create from a format:

    $startDate = "2015-05-12 15:49:06.821289";
    $start = new DateTime($startDate);
    echo $start->format('m/d/y');
    

提交回复
热议问题