我从字符串中提取日期。以下是我的代码。我最后得到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
答案 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 = '';}