由于我阅读了另一个有类似问题的主题,我不明白我的情况有什么问题日期排序 - 在这两种情况下,日期 03-14-2020 应该变成 2020-14-03 但变成 1970-01-01$dates = explode(" / ", $this->input->post('date'));print_r($dates);Array ( [0] => 03-14-2020 [1] => 03-20-2020 ) $newDate = array( 'start' => date("Y-m-d", strtotime($dates[0])), 'end' => date("Y-m-d", strtotime($dates[1])) );print_r($newDate)Array ( [start] => 1970-01-01 [end] => 1970-01-01 ) 即使这种方式显示不正确$date = DateTime::createFromFormat('d-m-Y', $dates[0]);print_r($date->format('Y-m-d'));2021-02-03
2 回答
HUH函数
TA贡献1836条经验 获得超4个赞
我使用 DateTime::createFromFormat 完成了它
$start = DateTime::createFromFormat('m-d-Y', $dates[0]);
$end = DateTime::createFromFormat('m-d-Y', $dates[1]);
$newDate = array(
'start' => $start->format('Y-m-d'),
'end' => $end->format('Y-m-d')
);
print_r($newDate) ;
Array ( [start] => 2020-03-14 [end] => 2020-03-20 )
千巷猫影
TA贡献1829条经验 获得超7个赞
$dates = array ('03-14-2020', '03-20-2020' );
print_r($dates);
$newDate = array(
'start' => date("Y-m-d", time($dates[0])),
'end' => date("Y-m-d", time($dates[1]))
);
print_r($newDate)
- 2 回答
- 0 关注
- 116 浏览
添加回答
举报
0/150
提交
取消