PHP DateTime __construct() Failed to parse time string (xxxxxxxx) at position x

后端 未结 5 1929

I had this construction error when trying to creating a new DateTime object using a timestamp:

Exception: DateTime::_construct(): Failed to parse

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 11:24

    You should use setTimestamp instead, if you hardcode it:

    $start_date = new DateTime();
    $start_date->setTimestamp(1372622987);
    

    in your case

    $start_date = new DateTime();
    $start_date->setTimestamp($dbResult->db_timestamp);
    

提交回复
热议问题