Avatar ·

How to convert seconds to Hours:Minutes:Seconds format in PHP?

Hi everyone! I'm new to PHP and came across this task: I have a variable that stores a number of seconds, for example 3665. I need to output this time in a readable HH:MM:SS format, i.e. 1:01:05. \n\nI tried simply dividing by 3600, 60 and using the remainder, but I'm getting nonsense. Here's my code:\n\n```php\n\n```\n\nThe problem is that hours are output as 1.0180555555556, and minutes as 1.0833333333333. I understand that rounding is needed, but if I just use intval, the remainders are lost. Tell me how to do it correctly? I need hours, minutes and seconds to be integers, and the format should have leading