时间戳转换工具

前言:

在扩展客服导单的时候,遇到了 PHP 处理 Excel 时间的问题。处理并记录一下。

问题

PHP 获取到的 Excel 的时间格式是:41728.732916667。当想要将其转换成 2014-03-30 17:35:24 格式时,遇到了困难。


解决方案

// 这里要注意 `.` 因为不具体到时间的话,是没有 `.` 的,而具体到时间之后,就有 `.` 了
if (preg_match('/^[\d.]*$/', $time)) {
// 正常的时间处理
if (strtotime($time)) {
return date('Y-m-d H:i:s', strtotime($time));
} else {
// 如果是 excel 的时间,则另外处理
return gmdate('Y-m-d H:i:s', ($time - 25569) * 86400);
}
}


联系我们 - 首页 - 关于我们
Copyright © 2017-2022 iteam. All Rights Reserved. Current version is 2.50.0.
粤ICP备17021424号
VV:46373 UV:165285 PV:515435