【发布时间】:2015-07-10 16:04:19
【问题描述】:
我正在从 excel 中读取一些数据并将它们导入数据库。但是遇到了一个奇怪的问题。除了日期部分,一切都很好。代码部分是:
$dob = $cells[$i][6];
echo $dob.'<br>';
$timestamp = strtotime($dob);
echo 'time- '.$timestamp;
echo 'time2- '.strtotime('01-01-2000');exit;
输出是:
01-01-2000
time- time2- 946677600
我在 excel 文件中使用的值与从输出中看到的 01-01-2000 完全相同。
我不明白为什么 strtotime 函数可以返回硬编码字符串版本的值,但不能返回从 excel 文件中读取的变量?
感谢您的帮助。
解决方案: 如果有人遇到同样的问题,我就是这样处理的。
$dob_temp = $cells[$i][6];
$dob_numbers = preg_replace("/[^0-9]/","",$dob_temp);
$timestamp = strtotime(substr($dob_numbers,0,2).'-'.substr($dob_numbers,2,2).'-'.substr($dob_numbers,4,4));
$dob = date('Y-m-d', $timestamp);
【问题讨论】:
标签: php strtotime import-from-excel