我正在从laravel后端的引导日期选择器中获取日期。
[start_date] => Array
(
[year] => 2018
[month] => 2
[day] => 1
)
[end_date] => Array
(
[year] => 2018
[month] => 4
[day] => 30
)
我想将日期转换为php日期,即
start_date = "2018-02-01";
end_date = "2018-04-30"
如果有人提供答案,请提供特定的代码或链接。
答案 0 :(得分:1)
您可以使用implode来避免长代码:
$get_start_date = implode('-',$RequestData['start_date'])
$get_end_date = implode('-',$RequestData['end_date'])
$start_date = date("Y-m-d", strtotime($get_start_date));
$end_date = date("Y-m-d", strtotime($get_end_date));
答案 1 :(得分:0)
您可以使用date_create PHP函数:
$start_date=date_create($date['start_date']->year.'-'.$date['start_date']->month.$date['start_date']->day);
$start_date=$start_date->format('Y-m-d')
$end_date=date_create($date['end_date']->year.'-'.$date['end_date']->month.$date['end_date']->day);
$end_date=$end_date->format('Y-m-d')
答案 2 :(得分:0)
您可以使用Carbon
$s_date = \Carbon\Carbon::create($start_date[0], $start_date[1],
$start_date[2],0,0,0);
答案 3 :(得分:0)
最好使用碳https://carbon.nesbot.com/docs/
$dt = Carbon::create($year, $month, $day);
echo $dt->toDateString();