Converting PHP time to seconds is very simple. We use the strtotime function. Let’s introduce it to you here. I hope the article can help you.
Convert the time string in the format of HH:MM:SS into seconds, you can use the date_parse function to parse specific time information.
<?php $time = '21:30:10'; $parsed = date_parse($time); $seconds = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second']; echo $seconds; ?>
More detailed examples, how many days/hours/minutes to convert
function get_stay_time($timestamp, $is_hour = 1, $is_minutes = 1) { $CI =& get_instance(); if(emptyempty($timestamp) || $timestamp <= 60) { return false; } $time = time(); $remain_time = $time - $timestamp; $day = floor($remain_time / (3600*24)); $day = $day > 0 ? $day.'天' : ''; $hour = floor(($remain_time % (3600*24)) / 3600); $hour = $hour > 0 ? $hour.'小时' : ''; if($is_hour && $is_minutes) { $minutes = floor((($remain_time % (3600*24)) % 3600) / 60); $minutes = $minutes > 0 ? $minutes.'分' : ''; return $day.$hour.$minutes; } if($hour) { return $day.$hour; } return $day; }
The above is the content of the example of converting PHP time into seconds, more For related content, please pay attention to the PHP Chinese website (www.php.cn)!