PHP结合了日期和时间字段以形成DateTime



我有3个单独的字段:

// date object in the format yyyy-mm-dd
$service_1_date 
// time object in the format 00:00:00
$booking->service_1_time_start
// time object in the format 00:00:00
$booking->service_1_time_end

我将它们设置为单独的字段,因为我在应用程序中分别操纵它们。

但是,当我创建一个Google日历事件时,我必须将DateTime对象以这样的值传递:

Event::create([
           'name' => 'New Booking',
           'startDateTime' => '',
           'endDateTime' => '',
        ]);

为了使我通过startDateTimeendDateTime参数,我必须首先组合我的日期和时间对象。所以我的问题是如何将日期和时间对象组合成一个日期对象?

它期望碳实例

使用它:

 $newDT = date('Y-m-d H:i:s', strtotime("$service_1_date $booking->service_1_time_start"));

最新更新