PHP 01/01/1970日期字段的问题

时间:2016-03-10 12:08:30

标签: php date datetime strtotime

我从字符串中提取日期。以下是我的代码。我最后得到only January 1, 1970。请帮我解决这个问题。你的帮助将不胜感激。

    $current = 'DATE OF : 23/03/1951 BENCH:';

    $DATEOF = preg_replace('/(.*)DATE OF (.*?)BENCH:(.*)/s', '$2', $current);

    if (!is_null($DATEOF)) {
        $oldDate = $DATEOF;
        $oldDateReplace = str_replace(array('!\s+!', '/^\s+/', '/\s+$/',':'), array('','','',''), trim($oldDate));

        $date = ''.$oldDateReplace.'';
        $timestamp = strtotime($date);
    if ($timestamp === FALSE) {
         $timestamp = strtotime(str_replace('/', '-', $date));
     }
     echo $newDate = date("F j, Y",$newDateM);

    }else{$newDate = '';}

    // print this date only January 1, 1970 i want this date 23/03/1951

1 个答案:

答案 0 :(得分:0)

使用以下代码

$current = 'DATE OF : 23/03/1951 BENCH:';

$DATEOF = preg_replace('/(.*)DATE OF (.*?)BENCH:(.*)/s', '$2', $current);

if (!is_null($DATEOF)) {
$oldDate = $DATEOF;
$oldDateReplace = str_replace(array('!\s+!', '/^\s+/', '/\s+$/',':'), array('','','',''), trim($oldDate));

$date = ''.$oldDateReplace.'';
$timestamp = strtotime($date);
if ($timestamp === FALSE) {
     $timestamp = strtotime(str_replace('/', '-', $date));
}
   echo $newDateM = date("m/d/Y",$timestamp);
   echo $newDate = date("F j, Y",$timestamp);

}else{$newDate = '';}