gpt4 book ai didi

Phpspreadsheet - 时间单元格检索为 float

转载 作者:行者123 更新时间:2023-12-03 23:22:09 24 4
gpt4 key购买 nike

我有一个有时间输入的excel文件。

  Mar 01, 2018  | Thursday  | 8:00 AM | 5:00 PM
Mar 02, 2018 | Friday | 8:00 AM | 5:00 PM

但是当我的代码尝试读取这些单元格时,输出变为浮点数(例如 8:00 AM 变为 0.33333333333333 )。这是我的代码
$date = $sheet->getCell("A".$row)->getValue();
$time_in = $sheet->getCell("C".$row)->getValue();
$time_out = $sheet->getCell("D".$row)->getValue();

echo "date: ".$date. //Mar 01, 2018
" time_in: ".$time_in. //becomes 0.333333333333333
" time_out: ".$time_out; //becomes 0.708333333333333

如何在不更改 phpspreadsheet 值的情况下按原样输出?我尝试查看 phpspreadsheet 文档,但没有找到解决方案。

最佳答案

谢天谢地,我刚刚找到了答案。

$in = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($time_in);
echo gmdate("g:i a", $in);

希望这对其他人有用。

关于Phpspreadsheet - 时间单元格检索为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49142511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com