How to include a digital clock using java script in a php page without "borrowing" it from any other site just like the one given in the code?

10,185

W3Schools has an excellent example in pure JavaScript:

<!DOCTYPE html>
<html>
<head>
<script>
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>
Share:
10,185
Akshay
Author by

Akshay

Updated on June 26, 2022

Comments

  • Akshay
    Akshay almost 2 years

    Need a method to get a digital clock without taking it from sites like 24timezones.com

    <script src="http://24timezones.com/timescript/maindata.js.php?city=1595976"language="javascript"></script>**strong text**
    <table width="8">
          <tr>
           <td width="83"><div id="flash_container_tt52b882f044241"></div>
            <script type="text/javascript">
            var flashMap = new SWFObject("http://24timezones.com/timescript/clock_digit_24.swf", "main", "1360", "70", "7.0.22", "#FFFFFF", true)
            flashMap.addParam("movie",      "http://24timezones.com/timescript/clock_digit_24.swf");
            flashMap.addParam("quality",    "high");
            flashMap.addParam("wmode",      "transparent");
            flashMap.addParam("flashvars",  "color=00CC00&logo=1&city=1595976");
            flashMap.write("flash_container_tt52b882f044241");
              </script></td>
              </tr>
            </table>