Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

PHP - PhpSpreadsheet not converting a date time stamp properly

I have an xlsx file that I upload to my web app and parse using PHP and PHPSpreadsheet. So far, I'm able to parse dates given that they're just the date, no time.

Here's the code I use:

$date_of_birth = PhpOfficePhpSpreadsheetSharedDate::excelToDateTimeObject($entry[5]);
$date_of_birth = $date_of_birth->format("Y-m-d");

Where $entry is an array of data that represents one row in the excel file I have. Kindly note that I use getFormattedValue() instead of getValue().

However, when I encounter something that has a timestamp, for example 7/18/1983 12:00:00 AM, I get the output 1900-01-07. For comparison, when I get a date like 12/6/14, the output is 2014-12-06, which is correct.

I'm not quite sure what I should do here as PhpSpreadsheet has very sparse documentation when it comes to this.

I can certainly just trim off the timestamp value and just have the script convert the date part, but I'm hoping to not have to resolve to that.

question from:https://stackoverflow.com/questions/65932036/php-phpspreadsheet-not-converting-a-date-time-stamp-properly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...