Switch to full style
JavaScript code examples
Post a reply

print clock using JavaScript

Fri Sep 16, 2011 11:39 pm

Time clock using JavaScript
Code:

<html>
<
title>java script clock</title>
<
head>
<
script language="JavaScript">
<!--

function showClock()
{
var thetime=new Date();

var hoursCounter=thetime.getHours();
var minutesCounter=thetime.getMinutes();
var secondsCounter=thetime.getSeconds();
var dayCounter=thetime.getDay();
var monthCounter=thetime.getMonth();
var todayDate=thetime.getDate();
var yearCounter=thetime.getYear();
var AM_PM=" ";

if (hoursCounter>=12)
    AM_PM="PM.";
else
    AM_PM="AM.";

if (hoursCounter>=13)
    hoursCounter-=12;

if (hoursCounter==0)
   hoursCounter=12;

if (secondsCounter<10)
 secondsCounter="0"+secondsCounter;

if (minutesCounter<10)
 minutesCounter="0"+minutesCounter;

if (dayCounter==0)
  dayCounter="SudayCounter";
if (dayCounter==1)
  dayCounter="ModayCounter";
if (dayCounter==2)
  dayCounter="Tuesday";
if (dayCounter==3)
  dayCounter="Wednesday";
if (dayCounter==4)
  dayCounter="Thursday";
if (dayCounter==5)
  dayCounter="Friday";
if (dayCounter==6)
  dayCounter="Saturday";

monthCounter+=1;

if (yearCounter<=99)
  yearCounter= "19"+yearCounter;

if ((yearCounter>99) && (yearCounter<2000))
 yearCounter+=1900;

document.getElementById("timediv").innerHTML=hoursCounter+": "+
minutesCounter+": "+secondsCounter+" "+AM_PM+" "+dayCounter+", "+monthCounter+"/"+todayDate+"/"+yearCounter;
// sleep for one second
setTimeout('showClock()',1000);

}
 

//-->
</script>
</head>

<body>

<table> 
<tr>
<td>Time:</td><td><div id="timediv" /></td>
</tr>
 </table>
<SCRIPT language="JavaScript">
<!--
showClock();
//-->
</SCRIPT>

</body>
</HTML>




Post a reply
  Related Posts  to : print clock using JavaScript
 Simple Clock using Date class and Threading     -  
 Help for Print using php     -  
 Print the ASCII Set     -  
 Print all files in a directory     -  
 Difference between PHP echo() and PHP print()?     -  
 Print all server variables     -  
 How to print a webcam picture in Jsp     -  
 Get union of two arrays set and print it     -  
 print element in 2d matrix     -  
 Print all MySQL status value     -  

Topic Tags

JavaScript Time