莫菲    

phpexcel读取时间格式

6年前发布  · 782 次阅读
  phpexcel 

excel中时间格式如上图所示,要使用phpexcel获取正确的时间格式:

$date参数为用phpexcel读取到的对应表格中的数值。

public static function excelTime($date){
    if(is_numeric($date)){
        $n = ceil(($date - 25569) * 3600 * 24); //转换成1970年以来的秒数
        $date_str = gmdate('Y-m-d H:i:s', $n);//格式化时间
        return $date_str;
    }
    return $date;
}

注:之前ceil方法位置处使用的是intal会出现在linux系统中23:59:59相差一秒变为 23:59:58的情况。