Click to See Complete Forum and Search --> : Modifying JavaScript Clock
KingG
05-06-2003, 08:02 PM
http://htmlgoodies.com/beyond/javatime.html
Is there a way to modify the actual time so it appear's x-hours/minute/seconds off from the actual time?
If not, would anyone know of a script that can already do this (without having to be run on the server itself)?
Charles
05-06-2003, 08:19 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
var offset = Date.ONE_HOUR;
Date.prototype.toString = function () {return [this.getHours() < 10 ? '0' + this.getHours() : this.getHours(), this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join (':')}
document.write('<form name="show"><div><input type="text" name="time"></div></form>');
setInterval('document.forms.show.time.value = new Date(new Date().getTime() + offset)', 0.2 * Date.ONE_SECOND);
// -->
</script>
KingG
05-14-2003, 07:34 PM
With this code, how would I change the time displayed so it will appear 3 hours behind the actual hour, 22 minutes behind the actual minute, and 12 seconds ahead of the actual number of seconds?
Charles
05-14-2003, 09:04 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
var offset = 3 * Date.ONE_HOUR - 22 * Date.ONE_MINUTE + 12 * Date.ONE_SECOND;
Date.prototype.toString = function () {return [this.getHours() < 10 ? '0' + this.getHours() : this.getHours(), this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join (':')}
document.write('<p id="time">Time: ', new Date(new Date().getTime() + offset), '</p>');
if (document.getElementById) setInterval("document.getElementById('time').innerHTML = 'Time: ' + new Date(new Date().getTime() + offset)", 0.2 * Date.ONE_SECOND);
// -->
</script>