我有两个从日期输入和时间输入发送的日期对象。
我想用日期输入中的 yyyy-mm-dd 和时间输入中的 hh-mm 生成一个 DateTime 对象。
从日期输入发送的数据
[search_from_date] => 2015-08-04T23:00:00.000Z
Run Code Online (Sandbox Code Playgroud)
从时间输入发送的数据
[search_from_time] => 1970-01-01T02:02:00.000Z
Run Code Online (Sandbox Code Playgroud)
我需要将这两个日期合并为:
2015-08-04 02:02
Run Code Online (Sandbox Code Playgroud)
我一直在玩弄炸线等,但无济于事,
任何帮助都会被应用
干杯
您可以从字符串创建两个 DateTime 对象,然后使用第二个对象设置第一个对象的时间。
$arr = ['search_from_date' => '2015-08-04T23:00:00.000Z', 'search_from_time' => '1970-01-01T02:02:00.000Z'];
$date = new DateTime($arr['search_from_date']);
$time = new DateTime($arr['search_from_time']);
$date->setTime($time->format('H'), $time->format('i'), $time->format('s'));
echo $date->format('r');
Run Code Online (Sandbox Code Playgroud)
这是一个带有示例的 eval.in - https://eval.in/424209
归档时间: |
|
查看次数: |
1017 次 |
最近记录: |