Home »
PHP »
PHP programs
PHP program to convert hours, minutes, and seconds into several seconds
Here, we are going to learn how to convert hours, minutes, and seconds into several seconds in PHP?
Submitted by Nidhi, on November 11, 2020
Here, we will convert hours, minutes, and seconds into the number of seconds and print the result on the webpage.
Program/Source Code:
The source code to convert hours, minutes, and seconds into the number of seconds is given below. The given program is compiled and executed successfully.
<?php
//PHP program to convert hours, minutes, and seconds
//into several seconds.
$hh = 1;
$mm = 48;
$ss = 50;
$seconds = $hh * 3600 + $mm * 60 + $ss;
print ("Number of seconds: " . $seconds);
?>
Output:
Number of seconds: 6530
Explanation:
In the above program, we created three variables $hh, $mm, and $ss that are initialized with 1, 48, and 50 respectively. Then we calculated the number of seconds and printed the result on the console screen.
TOP Interview Coding Problems/Challenges