使用phpExcel获取日期时间
我的列的格式为cell:dd/mm/yyyy hh:mm,当我阅读这些工作表时,我只需要获取该值的日期并保存在mysql中 默认情况下,我读取日期,并利用漏洞保存它,但日期的格式很奇怪 单元格中的列日期:使用phpExcel获取日期时间,php,datetime,phpexcel,Php,Datetime,Phpexcel,我的列的格式为cell:dd/mm/yyyy hh:mm,当我阅读这些工作表时,我只需要获取该值的日期并保存在mysql中 默认情况下,我读取日期,并利用漏洞保存它,但日期的格式很奇怪 单元格中的列日期:13/11/2017 00:01 我的代码: $inputFileType = PHPExcel_IOFactory::identify($inputFileName); $objReader = PHPExcel_IOFactory::createReader($inputFi
13/11/2017 00:01
我的代码:
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
//Get worksheet and built array with first row as header
$objWorksheet = $objPHPExcel->getActiveSheet();
//excel with first row header, use header as key
if($header){
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
}
else{
//excel sheet with no header
$namedDataArray = $objWorksheet->toArray(null,true,true,true);
}
43052.000717593
是MS Excel序列化时间戳值,是自1900年1月1日(或1904年1月1日,如果电子表格使用Mac日历)以来的天数计数
MS Excel使用格式掩码对该值进行格式化,您称之为dd/mm/yyyy hh:mm
,并将该值显示为13/11/2017 00:01
,这正是我从该格式掩码中所期望的
如果您希望以不同的格式设置日期;然后,您可以在调用rangeToArray()
之前更改格式掩码。Excel格式掩码yyyy-mm-dd
将仅以适当的格式提供日期
或者,获取序列化的时间戳值,然后使用PHPExcel\u Shared\u Date
的ExcelToPHP()
方法分别给出unix时间戳或PHP日期时间对象,然后可以使用PHP的Date()按需格式化
函数或日期时间对象的格式()
方法
$data_mailing_file = explode(" ", $value['field_date']);
$dataP = explode('/', $data_mailing_file[0]);
$data_save = $dataP[2].'-'.$dataP[1].'-'.$dataP[0];