本篇文章给大家带来的内容是关于phpexcel导入excel文件并对其日期单元格处理的代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
PHPExcel导入Excel文件,对Excel中日期单元格处理
/**
* 判断字符串是否是日期格式
* @param $date
* @param $format
* @return bool
*/
function is_date($date, $format = 'Y-m-d')
{
if (!$date || $date == '0000-00-00') return false;
$unix_time_1 = strtotime($date);
if (!is_numeric($unix_time_1)) return false; //非数字格式
$format_date = date($format, $unix_time_1);
$unix_time_2 = strtotime($format_date);
return ($unix_time_1 == $unix_time_2);
}
/**
* excel数据导入 日期格式化
* @param $date
* @return false|string
*/
function get_date_by_excel($date)
{
if (!$date || $date == '0000-00-00') return null;
$unix_time = \PHPExcel_Shared_Date::ExcelToPHP($date);
return ($unix_time
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!











