This option will reset the home page of this site. Restoring any closed widgets or categories.

Reset

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<1)
   nhours=12;
  if (nsecn<10)
   nsecn="0"+nsecn;
  if (nmins<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<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.5.7_846]
Rating: 0.0/10 (0 votes cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • Xerpi

Related posts:

  1. Write data to a page using javascript
  2. Javascript Clock
  3. Change webpage background color using javascript
  4. Simple php watermark script

Leave a Reply

Spam Protected