Does PHP have an inverse of the date() function (other than strtotime())?

前端 未结 7 537
别跟我提以往
别跟我提以往 2021-01-17 14:53

Is there a function that uses the date() format to interpret a string?

echo date(\'s-i-H d:m:Y\', 1304591364); // 34-29-17 05:05:2011

// Does t         


        
相关标签:
7条回答
  • 2021-01-17 15:36

    The accepted answer is right IMO, but you can also use the OO syntax: DateTime::createFromFormat eg:

    $dateTimeObject = \DateTime::createFromFormat('G:i', '9:30');
    $dateTimeObject->format('H:i');
    

    See http://php.net/manual/en/function.date.php for formatting guides, and http://php.net/manual/en/datetime.createfromformat.php for info on the method described above.

    0 讨论(0)
提交回复
热议问题