[英]PHPExcel returns a weird date format
When I use PHPExcel's getFormattedValue()
on a row / column that, in LibreOffice Calc, shows up as 02/19/2015 23:59:40
I get 42067.458524537
back. 当我在LibreOffice Calc中显示为
02/19/2015 23:59:40
的行/列上使用PHPExcel的getFormattedValue()
时,我得到了42067.458524537
。 How do I convert that to 02/19/2015 23:59:40
? 如何将其转换为
02/19/2015 23:59:40
?
My PHP code is as follows: 我的PHP代码如下:
<?php
include('/path/to/PHPExcel.php');
$filePath = 'filename.xlsx';
$inputFileType = PHPExcel_IOFactory::identify($filePath);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$excel = $objReader->load($filePath);
$worksheet = $excel->getSheet();
echo $worksheet->getCellByColumnAndRow(3, 4)->getFormattedValue();
MS Excel stores dates as a serialized value, a real number that is a count of the number of days since a baseline of either 1st January 1900 or 1st December 1904, depending on whether the spreadsheet was created using the Windows 1900 calendar or the Mac 1904 calendar. MS Excel将日期存储为一个序列化值,一个实数,它是自1900年1月1日或1904年12月1日基线以来的天数,具体取决于电子表格是使用Windows 1900日历还是使用Mac 1904创建的日历。
A serialized value of 42067.458524537 corresponds to a date of 4th March 2015 at 11:00:17 (with the Windows 1900 Calendar) 序列化的值42067.458524537对应于2015年3月4日11:00:17的日期(使用Windows 1900日历)
If you've used PHPExcel's getFormattedValue()
method, then it should convert the serialized value to a formatted date/time string based on the number format mask applied to that cell.... assuming that you didn't set loadDataOnly when loading the spreadsheet file. 如果您使用过PHPExcel的
getFormattedValue()
方法,则它应根据应用于该单元格的数字格式掩码将序列化的值转换为格式化的日期/时间字符串。...假设加载时未设置loadDataOnly电子表格文件。
If you need to convert the raw MS Excel serialized value to a unix timestamp or to a PHP DateTime object, then you can use the PHPExcel_Shared_Date::ExcelToPHP()
or PHPExcel_Shared_Date::ExcelToPHPObject()
methods respectively; 如果需要将原始MS Excel序列化的值转换为unix时间戳或PHP DateTime对象,则可以分别使用
PHPExcel_Shared_Date::ExcelToPHP()
或PHPExcel_Shared_Date::ExcelToPHPObject()
方法; then use the native PHP date()
of DateTime::format()
functionality to format it however you want. 然后使用
DateTime::format()
功能的本机PHP date()
进行DateTime::format()
如果需要)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.