使用 PhpSpreadsheet 读取时间问题
怎么使用 PhpSpreadsheet 读取excel,参考我的另一篇文章博客:使用 PhpSpreadsheet 读取 excel 文件内容
表里的时间格式是这样的
用 PhpSpreadsheet 的 $sheet->getCell('B1')->getValue();
获取的结果是这样的:
我们可以按下面这样处理一下:
$data = $sheet->getCell('B1')->getValue();
$toTimestamp = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($data);
$data = gmdate("Y-m-d H:i:s", $toTimestamp);
可以看到,成功转出原本格式的时间。然后我们可以继续用 strtotime()
将其转为时间戳格式。
当时,可以的话,最好是策划将其直接配置为时间戳格式。
本作品采用《CC 协议》,转载必须注明作者和本文链接