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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.