PHP日期导出为CSV格式 [英] PHP Date Export To CSV Format
本文介绍了PHP日期导出为CSV格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
导出之后,当我打开CSV时,您会注意到列L仅格式化一些正确的日期。这也发生在几个其他日期列。有什么我可以用PHP来确保所有日期都正确返回以下id我的功能:
After export and when I open the CSV up, you'll notice column L formats only some of the dates properly. This happend on a couple other date columns as well. Is there anything I can do with PHP to ensure all dates are returned properly? Below id my function:
public function formatDateCI($date) {
// If Birthdate Column
if(strlen($date) == 10){
$date = explode('-',$date);
$m = $date[0];
$d = $date[1];
$Y = $date[2];
$date = $Y.'-'.$m.'-'.$d;
}
$date = new DateTime($date);
// Final Format 1983-24-12 00:00:00
return date_format($date, 'Y-d-m H:i:s');
}
推荐答案
尝试:
date('Y-m-d H:i:s', strtotime($date));
而不是:
$date = new DateTime($date);
>
请务必尝试如果其他结构:
Be sure to try an if else structure:
if(strlen($date) == 10){
$date = explode('-',$date);
$M= $date[0];
$D = $date[1];
$Y = $date[2];
//this $date = $Y.'-'.$m.'-'.$d;
//or this =>
$date = date('Y-m-d H:i:s', mktime($h, $m, $s, $M, $D, $Y));
}else{
$date = date('Y-m-d H:i:s', strtotime($date));
}
return $date;
这篇关于PHP日期导出为CSV格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文