Facebook Twitter Reset

This Tutorial Has Been Viewed 1,411 Times.

Simple Javascript Clock

This is a small and very simple tutorial on how to create a clock for your website using  javascript.Just add the below code to the section of your website where you want the clock to be displayed

<span id="clock"></span>
<script type="text/javascript">
{
function startclock()//script from mistonline.in
  var thetime=new Date();
  var nhours=thetime.getHours();
  var nmins=thetime.getMinutes();
  var nsecn=thetime.getSeconds();
  var nday=thetime.getDay();
  var nmonth=thetime.getMonth();
  var ntoday=thetime.getDate();
  var nyear=thetime.getYear();
  var AorP = (nhours >= 12) ? "P.M." : "A.M.";
  if (nhours>=13)
    nhours-=12;
  if (nhours&lt;1)
   nhours=12;
  if (nsecn&lt;10)
   nsecn="0"+nsecn;
  if (nmins&lt;10)
   nmins="0"+nmins;
  switch (nday) {
    case 0 : nday = "Sunday"; break;
    case 1 : nday = "Monday"; break;
    case 2 : nday = "Tuesday"; break;
    case 3 : nday = "Wednesday"; break;
    case 4 : nday = "Thursday"; break;
    case 5 : nday = "Friday"; break;
    case 6 : nday = "Saturday"; break;
  }
  nmonth+=1;
  if (nyear< =99)
    nyear= "19"+nyear;
  if ((nyear>99) && (nyear&lt;2000))
   nyear+=1900;

  var clock_span = document.getElementById("clock");
  clock_span.innerHTML = nhours+":"+nmins+":"+nsecn+" "+AorP+" "+nday+", "+nmonth+"/"+ntoday+"/"+nyear;

setTimeout('startclock()',1000);
}

if (document.getElementById && document.createTextNode) {
  startclock();
}
</script>

Thanks :)

VN:F [1.9.13_1145]
Rating: 10.0/10 (2 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)
Simple Javascript Clock, 10.0 out of 10 based on 2 ratings

Incoming search terms:




You will also be interested in ,

No comments yet.

Leave a Comment

Spam protection by WP Captcha-Free

Affordable Seo PackagesSeo BlogEdu Backlinks
More in JavaScripts, scripts (87 of 143 articles)