In this tutorial we will show you how to convert seconds into minutes and hours using PHP. You may also like convert bytes intp kb, mb and gb using PHP.
CHECK OUT THIS TUTORIAL LIVE DEMO →
To Convert Seconds It Takes Only two Steps:-
- Make a PHP file and define markup and scripting
- Make a CSS file and define styling
Step 1. Make a PHP file and define markup and scripting
We make a PHP file and save it with a name convert.php
<?php if(isset($_POST['convert_seconds'])) { $time=$_POST['time']; $unit=$_POST['convert_unit']; if($unit == "Minutes") { $time = round($time / 60,4) . 'Min'; } if($unit == "Hours") { $time = round($time / 60 / 60,4) . 'Hours'; } } ?> <html> <head> <link type="text/css" rel="stylesheet" href="convert_style.css"/> </head> <body> <div id="wrapper"> <div id="convert_div"> <form method="post"action=""> <input type="text" name="time" placeholder="Enter Seconds"> <select name="convert_unit"> <option>Minutes</option> <option>Hours</option> </select> <br> <input type="submit" name="convert_seconds" value="Convert Seconds"> </form> <p><?php echo $time;?></p> </div> </div> </body> </html>
In this step we create a form for user to enter seconds and select which unit he wants seconds to convert and after submitting the form we get the value and convert unit and convert seconds to desirable unit then display the time.
You may also like convert HTML into PDF.
Step 2. Make a CSS file and define styling
We make a CSS file and save it with a name convert_style.css
body { margin:0 auto; padding:0px; text-align:center; width:100%; font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif; background-color:#F2F2F2; } #wrapper { margin:0 auto; padding:0px; text-align:center; width:995px; } #wrapper h1 { margin-top:50px; font-size:45px; color:#424242; } #wrapper h1 p { font-size:18px; } #convert_div input[type="text"] { width:400px; height:55px; padding-left:10px; font-size:18px; margin-bottom:15px; color:#424242; font-weight:bold; } #convert_div select { margin:0px; padding:0px; width:100px; height:55px; font-size:15px; margin-bottom:15px; color:#424242; font-weight:bold; } #convert_div input[type="submit"] { width:330px; height:45px; font-size:16px; font-weight:bold; background-color:#6E6E6E; color:white; border:none; box-shadow:0px 4px 0px 0px #585858; border-radius:3px; }
That's all, this is how to convert seconds into minutes and hours using PHP. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery