我要`start_time`和`end_time`算这个怎么算?
I want to `start_time` and `end_time` count how can get this?
如何计算 start_time
和 end_time
之间的时间
$time_all = Carbon::now()->toArray();
if ($input['type'] == 'start') {
/* $data = [
'start_time' => $time, 'contract_id' => $input['job_id'],'engineer_id' => $userid, 'type' => 'start'
];*/
$start_time = JobTimingLog::create([
'start_time' => $time, 'contract_id' => $input['job_id'],'engineer_id' => $userid, 'type' => 'start'
])->id;
$arr = array("status" => 200, "message" => "start_time Add Successfully", "data" => array('start_time' => $time, 'id' => $start_time));
} else if ($input['type'] == 'end') {
$data_end = DB::table('job_timing_logs')->where('contract_id', $input['job_id'])->where('id', $input['id'])->update(['end_time' => $time, 'type' => 'end']);
$arr = array("status" => 200, "message" => "end_time update Successfully", "data" => $times);
}
现在我想在 start_time 和 end_time
之间数
您可以使用 Carbon 的 difference 方法来获取两个 Carbon 对象之间的差异。
例如,如果您想在 CarbonInterval 对象中区分 $start_date
和 $end_date
,您可以这样做:
$start_date->diffAsCarbonInterval($end_date)
由于您没有指定从哪里获得 $time
变量内容以及它的格式,我假设 $time
是开始日期时间,$end_time
是结束日期datetime 并且您想计算这两者之间的时差。可以使用 Carbon difference 包来完成,如下所示:
// Assume $time = '2019-12-06 00:00:00' and $end_time = '2019-12-06 18:00:00'
$start_time = Carbon::parse($time); // Parse the datetime to Carbon object first
$end_time = Carbon::parse($end_time);
$diff_in_hours = $start_time->diffInHours($end_time);
$diff_in_minutes = $start_time->diffInMinutes($end_time);
$diff_in_seconds = $start_time->diffInSeconds($end_time);
如何计算 start_time
和 end_time
之间的时间
$time_all = Carbon::now()->toArray();
if ($input['type'] == 'start') {
/* $data = [
'start_time' => $time, 'contract_id' => $input['job_id'],'engineer_id' => $userid, 'type' => 'start'
];*/
$start_time = JobTimingLog::create([
'start_time' => $time, 'contract_id' => $input['job_id'],'engineer_id' => $userid, 'type' => 'start'
])->id;
$arr = array("status" => 200, "message" => "start_time Add Successfully", "data" => array('start_time' => $time, 'id' => $start_time));
} else if ($input['type'] == 'end') {
$data_end = DB::table('job_timing_logs')->where('contract_id', $input['job_id'])->where('id', $input['id'])->update(['end_time' => $time, 'type' => 'end']);
$arr = array("status" => 200, "message" => "end_time update Successfully", "data" => $times);
}
现在我想在 start_time 和 end_time
之间数您可以使用 Carbon 的 difference 方法来获取两个 Carbon 对象之间的差异。
例如,如果您想在 CarbonInterval 对象中区分 $start_date
和 $end_date
,您可以这样做:
$start_date->diffAsCarbonInterval($end_date)
由于您没有指定从哪里获得 $time
变量内容以及它的格式,我假设 $time
是开始日期时间,$end_time
是结束日期datetime 并且您想计算这两者之间的时差。可以使用 Carbon difference 包来完成,如下所示:
// Assume $time = '2019-12-06 00:00:00' and $end_time = '2019-12-06 18:00:00'
$start_time = Carbon::parse($time); // Parse the datetime to Carbon object first
$end_time = Carbon::parse($end_time);
$diff_in_hours = $start_time->diffInHours($end_time);
$diff_in_minutes = $start_time->diffInMinutes($end_time);
$diff_in_seconds = $start_time->diffInSeconds($end_time);