方式一:
$end_time = $objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();
$t1 = intval(($end_time - 25569) * 3600 * 24); //转换成1970年以来的秒数
$end_time = gmdate('Y-m-d H:i:s', $t1);
方式二:
//所以为了不出问题导入之前用该函数处理一下就可以了
function excelTime($date, $time = false)
{
if (function_exists('GregorianToJD')) {
if (is_numeric($date)) {
$jd = GregorianToJD(1, 1, 1970);
$gregorian = JDToGregorian($jd + intval($date) - 25569);
$date = explode('/', $gregorian);
$date_str = str_pad($date [2], 4, '0', STR_PAD_LEFT)
. "-" . str_pad($date [0], 2, '0', STR_PAD_LEFT)
. "-" . str_pad($date [1], 2, '0', STR_PAD_LEFT)
. ($time ? " 00:00:00" : '');
return $date_str;
}
} else {
$date = $date > 25568 ? $date + 1 : 25569;
/*There was a bug if Converting date before 1-1-1970 (tstamp 0)*/
$ofs = (70 * 365 + 17 + 2) * 86400;
$date = date("Y-m-d H:i:s", ($date * 86400) - $ofs) . ($time ? " 00:00:00" : '');
}
return $date;
}
$rw_date_strat = $objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();
$rw_date_end = $objPHPExcel->getActiveSheet()->getCell("D" . $j)->getValue();
if (is_object($rw_date_strat)) $rw_date_strat = $rw_date_strat->__toString();
if (is_object($rw_date_end)) $rw_date_end = $rw_date_end->__toString();
if ($title && $number && $rw_date_strat && $rw_date_end) {
$arr = array(
"rw_date_strat" => excelTime($rw_date_strat),
"rw_date_end" => excelTime($rw_date_end),
);
$infoArray["subjects"][] = $arr;
}