来自Excel工作表(CSV)的PHP解析日期列 [英] PHP parse date column from excel sheet (CSV)
本文介绍了来自Excel工作表(CSV)的PHP解析日期列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了具有日期字段的CSV文件,格式为12-08-2018.当我在Excel工作表中打开csv文件时,它将显示并以12/AUG/2018格式保存到文件.
I created CSV file having date field in format 12-08-2018. When I opened csv file in Excel sheet it displays and saves in format 12/AUG/2018 to file.
当我尝试解析时,我错了:
When I am trying to parse it gives me wrong:
<?php
echo date('Y-m-d',strtotime('12/AUG/2018')); // 1969-12-31
?>
因此,什么是处理来自Excel工作表的日期解析的最佳方法.
So, What could be the best way to handle parsing of date coming form excel sheet.
推荐答案
使用 createFromFormat 函数
$date = DateTime::createFromFormat('d/M/Y', '12/AUG/2018');
echo $date->format('Y-m-d'); // 2018-08-12
这篇关于来自Excel工作表(CSV)的PHP解析日期列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文