PHP中excel时间转换

这几天弄了一个项目需要做excel导入功能, 导入的时候发现excel的时间字段存储的好像不是unix时间戳。

Microsoft Excel stores dates as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900.

就是excel设1900年1月1日序号为1,存储的为设置时间于1900/1/1相隔多少

按天计算相差工具

数据库存储的unix时间戳是从1970年开始的秒数

所以只需要写个转换方法即可

方案

1
2
3
4
$t = 41807.66; //读取到的值
$n = intval(($t - 25569) * 3600 * 24); //转换成1970年以来的秒数
echo gmdate('Y-m-d H:i:s',$n);//格式化时间,不是用date哦, 时区相差8小时的
// gmdate() 函数格式化 GMT/UTC 日期和时间,并返回格式化的日期字符串
 上一篇

sso