Creating new Date Time from string

前端 未结 2 885
醉梦人生
醉梦人生 2020-12-09 14:59

I have a string which is \'23/05/2013\' and I wanted to create a new Date Time object from this, so I did:

new \\DateTime(\'23/05/2013\');

2条回答
  •  甜味超标
    2020-12-09 16:00

    If you want to use the object normally rather than statically try this:

    $datetime = new DateTime();
    $newDate = $datetime->createFromFormat('d/m/Y', '23/05/2013');
    

    then you can use it like normal:

    echo $newDate->format('Y-m-d');
    

提交回复
热议问题