on-internet
← Community

Why does this code to convert PT#H#M#S timestamps to HH:MM:SS in PHP drop the seconds from the output?

Stack Overflow ·

I want to convert PT2H34M25S to 2:34:25 (for example). I searched online, and found this code. function covtime($youtube_time){ preg_match_all('/(\d+)/',$youtube_time,$parts); $hours = floor($parts[0][0]/60); $minutes = $parts[0][0]%60; $seconds = $parts[0][1]; if($hours != 0) return $hours.':'.$minutes.':'.$seconds; else return $minutes.':'.$seconds; } but this code only give me HH:MM. Why is that? How can I get it to include the SS values, too?

Comments

Sign in or sign up to comment and upvote.

No comments yet.