<?php
function parseDate($dateValue)
{
$dateFormats = array(
'D, d M y H:i:s T',
'D, d M Y H:i:s T',
'D, d-M-y H:i:s T',
'D, d-M-Y H:i:s T',
'D, d-m-y H:i:s T',
'D, d-m-Y H:i:s T',
'D M j G:i:s Y',
'D M d H:i:s Y T',
);
foreach ($dateFormats as $dateFormat) {
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
return $date;
}
}
return date_create($dateValue, new \DateTimeZone('GMT'));
}
$dates = array(
array('Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 GMT'),
array('Fri Jul 31 08:49:37 2020', 'Friday, 31-Jul-2020 08:49:37 GMT'),
);
foreach ($dates as $date) {
echo parseDate($date[0])->format(\DateTime::COOKIE) . "\n";
}
preferences:
23.22 ms | 404 KiB | 5 Q