Home »
PHP »
PHP Programs
PHP program to convert seconds into hours, minutes, and seconds
Here, we are going to learn how to convert seconds into hours, minutes, and seconds in PHP?
Submitted by Nidhi, on November 11, 2020 [Last updated : March 13, 2023]
Converting Seconds to Hours, Minutes, and Seconds
Here, we will convert the number of seconds into hours, minutes, and seconds.
PHP code to convert seconds to hours, minutes, and seconds
The source code to convert seconds into hours, minutes, and seconds is given below. The given program is compiled and executed successfully.
<?php
//PHP program to convert seconds into
//hours, minutes, and seconds
$seconds = 6530;
$secs = $seconds % 60;
$hrs = $seconds / 60;
$mins = $hrs % 60;
$hrs = $hrs / 60;
print ("HH:MM:SS-> " . (int)$hrs . ":" . (int)$mins . ":" . (int)$secs);
?>
Output
HH:MM:SS-> 1:48:50
Explanation
In the above program, we created a variable $seconds, which is initialized with 6530 seconds. Then we converted the seconds into hours, minutes, and seconds respectively.
In the above examples, we used the following PHP topics:
PHP Class & Object Programs »