PDA

View Full Version : [DHTML] Scientific Millisecond Clock



techno_race
04-08-2007, 01:22 AM
1) CODE TITLE: Scientific Millisecond Clock

2) AUTHOR NAME/NOTES: techno_race

3) DESCRIPTION: A digital clock that measures down to the millisecond.

4) Attached.

mburt
04-08-2007, 01:29 AM
Good Lord, you raped one of the easiest scripts to write: :p

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Millisecond Clock</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
Number.prototype.pad = function(n) {
for(var r = this.toString(); r.length < n; r = 0 + r);
return r;
};
function updateClock() {
var now = new Date();
var milli = now.getMilliseconds(),
sec = now.getSeconds(),
min = now.getMinutes(),
hou = now.getHours(),
mo = now.getMonth(),
dy = now.getDate(),
yr = now.getFullYear();
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var tags = ["mon","d","y","h","m","s","mi"],
corr = [months[mo],dy,yr,hou.pad(2),min.pad(2),sec.pad(2),milli];
for (var i=0;i<tags.length;i++)
document.getElementById(tags[i]).firstChild.nodeValue = corr[i];
}

function initClock() {
updateClock();
window.setInterval("updateClock()", 1);
}
</script>
</head>
<body onLoad="initClock()">
<a id="mon">January</a>
<a id="d">1</a>,
<a id="y">0</a>
<a id="h">12</a>
:
<a id="m">00</a>:
<a id="s">00</a>:
<a id="mi">000</a>
</body>
</html>

techno_race
04-08-2007, 01:34 AM
Yes, I made it the longest possible so it would look more complicated. :p

mburt
04-08-2007, 01:41 AM
Good job, 'ya done well.