PHPECXCLE导入时间格式误转成数字

查了半天,原因就不说了,直接写解决方法

function excelTime($days, $time=false){
                    if(is_numeric($days)){
                        //based on 1900-1-1
                        $jd = GregorianToJD(1, 1, 1970);
                        $gregorian = JDToGregorian($jd+intval($days)-25569);
                        $myDate = explode('/',$gregorian);
                        $myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)
                            ."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)
                            ."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT)
                            .($time?" 00:00:00":'');
                        return $myDateStr;
                    }
                    return $days;
                }
引入这个方法,在设置值的时候

$days = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
$data['receiveDate'] = excelTime($days, $time=false);
改一下就可以了

随机浏览