Reputation: 462
I Want to convert this date " Apr 11 16:21:29.219 2019 GMT" to timestamp in PHP ,
This is my code :
$date = \DateTime::createFromFormat('M d H:i:s.u Y' ,
date_format(new \DateTime("Apr 11 16:21:29.219 2019 GMT)") ));
$response_time = strtotime($matches[1]);
But the result is null , Any ideas please ? Thank You !
Upvotes: 2
Views: 47
Reputation: 147166
You have a couple of issues, you shouldn't be attempting to make a DateTime
object directly from the string (that's what \DateTime::createFromFormat
is for) and you are missing the required e
format character to match the GMT
part of the string. Try this:
$date = \DateTime::createFromFormat('M d H:i:s.u Y e', "Apr 11 16:21:29.219 2019 GMT");
echo $date->format('Y-m-d H:i:s.u');
Output:
2019-04-11 16:21:29.219000
Upvotes: 5