Dynadot — .com Registration $8.99

Javascript live clock

Spacemail by SpaceshipSpacemail by Spaceship
Watch

axilant

Account Closed
Impact
28
Save this as: clock.js

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:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
•••
Yes, my mistake ;)

Change the id to time instead of clock in the body

Fixed it above.
 
0
•••
Ok, I edited and uploaded...But still, comes up blank. ;)
 
0
•••
Hmm... use the new body code in the above... http://phpprint.com it works perfectly fine O.o same code... :-/
 
0
•••
you could also try this it's without the formatting:

<script type="tex/tjavascript">
function start_time(){
var nDate = new DATE();
var elem = document.getElementById ? document.getElementById("box"):((document.all) ? document.all("box"):null);
if(elem){
elem.innerText = nDate;
}
setTimeout("start_time()",100);
}
</script onload>
<body onload="start_time()">
<div id = "box"></div>
</body>
 
0
•••
Nice tip.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back