Code:
<script type="text/javascript">
Number.prototype.pad = function(n) {
return (new Array(1 + n - this.toString().length)).join("0") + this;
};
Date.prototype.getTwelveHourStamp = function() {
var hours = this.getHours(),
mins = this.getMinutes().pad(2),
ext = hours >= 12 ? "PM" : "AM";
return (hours % 12) + ":" + mins + ext;
};
setInterval((function(f) { f(); return f; })
(function() { document.getElementById("clock").firstChild.nodeValue = (new Date()).getTwelveHourStamp(); }), 10000);
</script>
Have an element somewhere to catch it:
Code:
<span id="clock"> </span>
Place the Javascript code after the element.
Edit: Nile: try to avoid innerHTML, it's non-standard and leads to horrible code if used in large quantities. Additionally, eval() (which is what happens behind the scenes just about wherever you see a string of Javascript code) is very slow and leads to most of the same problems. Please read my list of common coding mistakes and the links therein.
setInterval("timein()",10000);
window.onload = function () { timein(); };
The former would be better written as setInterval(timein, 10000), the latter as onload = timein.
Bookmarks