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 [Last updated : March 13, 2023]

Converting Hours, Minutes, and Seconds into Total seconds

Here, we will convert hours, minutes, and seconds into the number of seconds and print the result on the webpage.

PHP code to hours, minutes, and seconds into total seconds

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.

PHP Class & Object Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.