12. PHP Program to convert seconds into Hours and Minutes.
How does this program work?
- In this program you will learn about how to convert seconds into Hours and Minutes using PHP.
- In this program first user has to enter how many seconds that to be convert into hours and minutes.
- This program perform mathematical calculations and display the result.
Here is the code
<html>
<head>
<title>PHP Program To convert seconds into hours and minutes</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter how many seconds"/>
</td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$s = $_POST['num'];
$h = $s/3600; // To convert seconds into hours
$m = $s/60; // To convert seconds into minutes
$precision = 3;
echo $s." seconds = ".number_format($h, $precision) ." hour";
echo $s." seconds = ".number_format($m, $precision) ." minutes";
return 0;
}
?>
</body>
</html>