axilant
Account Closed
- Impact
- 28
Save this as: clock.js
Save this as: index.htm
This should work in all browsers. Been tested in ie 6, and firefox (newest version)
Any questions or comments please post here.
Code:
//Coded by axilant[at]gmail.com
function clock() {
var curtime = new Date;
var hours = curtime.getHours();
if(hours < 10)
{
var hourstring = "0" + hours+toString();
}
else
{
var hourstring = hours.toString();
}
var minutes = curtime.getMinutes();
if(minutes < 10)
{
var minutestring = "0" + minutes.toString();
}
else
{
var minutestring = minutes.toString();
}
var seconds = curtime.getSeconds();
if(seconds < 10)
{
var secondstring = "0" + seconds.toString();
}
else
{
var secondstring = seconds.toString();
}
var timestring = hourstring + ":" + minutestring + ":" + secondstring;
var timeplace = document.getElementById("time");
timeplace.childNodes[0].nodeValue = timestring;
setTimeout('clock()', 1000);
}
setTimeout('clock()', 1000);
Save this as: index.htm
Code:
<html lang="en">
<head>
<script src="clock.js">
</head>
<body>
<h2>Time:<div id="time">00:00:00</div></h2>
</body>
</html>
This should work in all browsers. Been tested in ie 6, and firefox (newest version)
Any questions or comments please post here.
Last edited:






