PHP - Simple Timestamp Converter

In this tutorial we will create a Simple Timestamp Converter Combining Two Arrays using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding...

Getting started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. </head>
  7. <body>
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  11. </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">PHP - Simple Timestamp Converter</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-3"></div>
  18. <div class="col-md-6">
  19. <form method="POST">
  20. <div class="form-group">
  21. <label>Timestamp:</label>
  22. <input type="number" value="<?php echo time();?>" name="time" class="form-control" readonly="readonly"/>
  23. </div>
  24.  
  25. <center><button class="btn btn-primary" name="convert"><span class="glyphicon glyphicon-random"></span> Convert</button></center>
  26. </form>
  27. <br />
  28. <?php include 'converter.php'?>
  29. </div>
  30. </div>
  31. </body>
  32. </html>

Creating the Main Function

This code contains the main function of the application. This code will automatically convert the timestamp into a human readable format. To do this just copy and write the code inside the text editor, then save it as converter.php.
  1. <?php
  2. if(ISSET($_POST['convert'])){
  3. $time = $_POST['time'];
  4.  
  5. $datetime = "F d, Y H:i:s A";
  6.  
  7. $date = new DateTime();
  8. $date->setTimestamp($time);
  9.  
  10. $newDate = $date->format($datetime);
  11. echo "<h4>The actual Datetime is:</h4>";
  12. echo "<center><h3 class='text-success'>".$newDate."</h3></center>";
  13. }
  14. ?>
There you have it we successfully created Simple Timestamp Converter using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment