Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Javascript live clock

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

Change the id to time instead of clock in the body

Fixed it above.
 
0
Close
Ok, I edited and uploaded...But still, comes up blank. ;)
 
0
Close
Hmm... use the new body code in the above... http://phpprint.com it works perfectly fine O.o same code... :-/
 
0
Close
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
Close
Nice tip.
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back