I have a specific date format that i need to convert to a normal looking date.

strtotime() isnt parsing it correctly.

$fulldate = 'Tue Feb 04 2014 09:30:00 GMT-0800 (Pacific Standard Time)';

echo $fulldate.'<br />';
echo strtotime($fulldate).'<br />';
echo date('Y-m-d g:i a', strtotime($fulldate));

Any Ideas?

有帮助吗?

解决方案

You can simply use a DateTime object:

<?php
    $fulldate = 'Tue Feb 04 2014 09:30:00 GMT-0800 (Pacific Standard Time)';
    //remove everything between the brackets
    $dateString = preg_replace("/\([^)]+\)/","",$fulldate);
    //now, get your date object
    $date = new DateTime($dateString);
    echo $date->format('Y-m-d H:i:s');
?>

Try the Fiddle here: http://ideone.com/odwtUH

其他提示

It's not a standard date format because of the last part (between the brackets).

One idea:

$tokens = explode("(", $fulldate);
array_pop($tokens);
$fulldate = trim(join("(", $tokens));
echo strtotime($fulldate);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top