Skip to main content

Simple Running Time using PHP and Javascript


This tutorial will show you how to create a running time using PHP and Javascript. This tutorial does not include a good design but will give you knowledge on how to create a simple running time.

Creating our Time Script

This script creates our running time. In this script, we have also included a small PHP code to show our running time. So, for us to show the time in our desired page, we just need to include the script. To create the script, open your HTML code editor and paste the code below after the tag. We name this script as "time.php".

  1. <span id=tick2>
  2. <script>
  3. function show2(){
  4. if (!document.all&&!document.getElementById)
  5. return
  6. thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2
  7. var Digital=new Date()
  8. var hours=Digital.getHours()
  9. var minutes=Digital.getMinutes()
  10. var seconds=Digital.getSeconds()
  11. var dn="PM"
  12. if (hours<12)
  13. dn="AM"
  14. if (hours>12)
  15. hours=hours-12
  16. if (hours==0)
  17. hours=12
  18. if (minutes<=9)
  19. minutes="0"+minutes
  20. if (seconds<=9)
  21. seconds="0"+seconds
  22. var ctime=hours+":"+minutes+":"+seconds+" "+dn
  23. thelement.innerHTML=ctime
  24. setTimeout("show2()",1000)
  25. }
  26. window.onload=show2
  27. //-->
  28. </script>
  29. </span>
  31. <?php
  32. $date = new DateTime();
  33. echo $date->format('l -- F j, Y');
  34. ?>

Creating our Show Page

Lastly, we create a page where we want to show our time. To create the page, open your HTML code editor and paste the code below after the tag. We name this page as "index.php".

  2. <html>
  3. <head>
  4. <title>Simple Running Time using PHP</title>
  5. </head>
  6. <body>
  7. <?php include ('time.php'); ?>
  8. </body>
  9. </html>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.