Convert String To date in PHP

后端 未结 9 2029
清酒与你
清酒与你 2020-12-15 08:54

How can I convert this string 05/Feb/2010:14:00:01 to unixtime ?

9条回答
  •  -上瘾入骨i
    2020-12-15 09:30

    Simple exploding should do the trick:

    $monthNamesToInt = array('Jan'=>1,'Feb'=>2, 'Mar'=>3 /*, [...]*/ );
    $datetime = '05/Feb/2010:14:00:01';
    list($date,$hour,$minute,$second) = explode(':',$datetime);
    list($day,$month,$year) = explode('/',$date);
    
    $unixtime = mktime((int)$hour, (int)$minute, (int)$second, $monthNamesToInt[$month], (int)$day, (int)$year);
    

提交回复
热议问题