• We just launched and are currently in beta. Join us as we build and grow the community.

PHP - Simple Timestamp Converter

GorillaZ

Mining Pool Operator
G Rep
0
0
0
Rep
0
G Vouches
0
0
0
Vouches
0
Posts
119
Likes
50
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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. <center><button class="btn btn-primary" name="convert"><span class="glyphicon glyphicon-random"></span> Convert</button></center>
  25. </form>
  26. <br />
  27. <?php

    include

    'converter.php'

    ?>
  28. </div>
  29. </div>
  30. </body>
  31. </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. $datetime

    =

    "F d, Y H:i:s A"

    ;

  5. $date

    =

    new

    DateTime(

    )

    ;
  6. $date

    ->

    setTimestamp

    (

    $time

    )

    ;

  7. $newDate

    =

    $date

    ->

    format

    (

    $datetime

    )

    ;
  8. echo

    "<h4>The actual Datetime is:</h4>"

    ;
  9. echo

    "<center><h3 class='text-success'>"

    .

    $newDate

    .

    "</h3></center>"

    ;
  10. }
  11. ?>

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!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,340

323,349

Top