PHP时间处理以TimeStamp为主。字符串转换可以通过格式符来控制。
$date=new DateTime('2022-02-24T22:11+08:00'); echo $date->format('Y-m-d\TH:i:s') . "\n";
function timestamp_to_datetime(int $timestamp){date_default_timezone_set('PRC'); return date("Y-m-d H:i:s",time());}
$code='421126'; query_obsTime_recent2($conne,$code); $row1=$conne->rst->fetch_row(); $row2=$conne->rst->fetch_row(); echo $row1[0],"\n"; echo $row2[0],"\n"; date_default_timezone_set('PRC'); $dat1=strtotime($row1[0]); $dat2=strtotime($row2[0]); echo $dat1,"\n"; echo $dat2,"\n"; echo $dat1-$dat2,"\n";2022-05-07T20:16+08:002022-05-06T16:11+08:0016519257601651824660101100
'2022-02-24T22:11+08:00'可以转换成时间,无需自己写解析函数。