我想转换我从$scheduleTime = Carbon::createFromTimestampUTC($scheduleTimestamp)->toTimeString();
获得的时间,目前正在给我07:32:40
现在我只想使用碳库将其转换为秒数这是可能的,如果是,那么如何?
答案 0 :(得分:2)
你可以使用
arr_A
以分钟或
显示时间$scheduleTime =\Carbon\Carbon::createFromTimestampUTC($scheduleTimestamp)->diffInMinutes()
将其显示在第二个
中答案 1 :(得分:2)
private function convertTimeToSecond(string $time): int
{
$d = explode(':', $time);
return ($d[0] * 3600) + ($d[1] * 60) + $d[2];
}
例如,两年后...
答案 2 :(得分:1)
你可以试试这个 它只会返回秒数
$scheduleTime =\Carbon\Carbon::createFromTimestampUTC($scheduleTimestamp)->second;
或
$scheduleTime =\Carbon\Carbon::createFromTimestampUTC($scheduleTimestamp)-> diffInSeconds();
答案 3 :(得分:1)
secondsSinceMidnight()
,你很高兴。
$scheduleTimeSeconds = Carbon::createFromTimestampUTC($scheduleTimestamp)->secondsSinceMidnight();
答案 4 :(得分:0)
试试这个,
$scheduleTime = Carbon::createFromTimestampUTC($scheduleTimestamp)->toTimeString();
$sec = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $scheduleTime);
sscanf($sec, "%d:%d:%d", $hours, $minutes, $seconds);
$time_seconds = $hours * 3600 + $minutes * 60 + $seconds;