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

Here, we will convert the number of seconds into hours, minutes, and seconds.

Program/Source Code:

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.






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.