I tried convert to timestamp but not working, My code is below
我尝试转换为时间戳但不能正常工作,我的代码如下
$date = $objPHPExcel->getActiveSheet()->getCell('A' . $x)->getFormattedValue();//output value is 9/Feb/16
echo strtotime($date);//return value is empty
It's return empty value. I want to compare Excel sheet date and PHP returned date. Excel sheet returned date is like this ->
9/Feb/16
它返回空值。我想比较Excel工作表日期和PHP返回日期。 Excel工作表返回日期是这样的 - > 9 / Feb / 16
3 个解决方案
#1
2
If the value in the cell is an MS Excel serialized timestamp, then you can get the "raw" value from the cell
如果单元格中的值是MS Excel序列化时间戳,则可以从单元格中获取“原始”值
$date = $objPHPExcel->getActiveSheet()
->getCell('A' . $x)->getValue();
which should return a number like 42409 for 2nd February 2016
这应该返回2016年2月2日的42409号码
Then use the built-in date/time conversion functions to convert that either to a unix timestamp, or to a PHP DateTime object
然后使用内置的日期/时间转换函数将其转换为unix时间戳或PHP DateTime对象
$date = PHPExcel_Shared_Date::ExcelToPHP($date); // returns a unix timestamp
echo date('Y-m-d H:i:s', $date);
or
$date = PHPExcel_Shared_Date::ExcelToPHPObject($date); // returns a DateTime object
echo $date->format('Y-m-d H:i:s');
#2
2
You just need to change slashes to minus symbol so strtotime
will recognize you $date as date
您只需要将斜杠更改为减号,这样strtotime就会将$ date视为日期
$date = str_replace('/','-',$date);
echo strtotime($date); //output 1454976000
#3
1
$d = DateTime::createFromFormat('j/M/y', '9/Feb/16');
echo $d->getTimestamp();
#1
2
If the value in the cell is an MS Excel serialized timestamp, then you can get the "raw" value from the cell
如果单元格中的值是MS Excel序列化时间戳,则可以从单元格中获取“原始”值
$date = $objPHPExcel->getActiveSheet()
->getCell('A' . $x)->getValue();
which should return a number like 42409 for 2nd February 2016
这应该返回2016年2月2日的42409号码
Then use the built-in date/time conversion functions to convert that either to a unix timestamp, or to a PHP DateTime object
然后使用内置的日期/时间转换函数将其转换为unix时间戳或PHP DateTime对象
$date = PHPExcel_Shared_Date::ExcelToPHP($date); // returns a unix timestamp
echo date('Y-m-d H:i:s', $date);
or
$date = PHPExcel_Shared_Date::ExcelToPHPObject($date); // returns a DateTime object
echo $date->format('Y-m-d H:i:s');
#2
2
You just need to change slashes to minus symbol so strtotime
will recognize you $date as date
您只需要将斜杠更改为减号,这样strtotime就会将$ date视为日期
$date = str_replace('/','-',$date);
echo strtotime($date); //output 1454976000
#3
1
$d = DateTime::createFromFormat('j/M/y', '9/Feb/16');
echo $d->getTimestamp();