/    Sign up×
Community /Pin to ProfileBookmark

Live clock – Set start time

How do I set a live clock, i.e. one that updates automatically in hours minutes and seconds, how do I set it to start at the time I tell it, rather than one retrieived from the users computer? I want to input a timestamp as it’s start point, if possible… then I want it to count up from my specified time live. (looping to update each second).

This is the clock that uses the user’s computer time:

<!– Begin
function clock() {
if (!document.layers && !document.all) return;
// right here I’d like to put in my own date //
var digital = new Date();
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
var amOrPm = “AM”;
if (hours > 11) amOrPm = “PM”;
if (hours > 12) hours = hours – 12;
if (hours == 0) hours = 12;
if (minutes <= 9) minutes = “0” + minutes;
if (seconds <= 9) seconds = “0” + seconds;
dispTime = hours + “:” + minutes + “:” + seconds + ” ” + amOrPm;
if (document.layers) {
document.layers.pendule.document.write(dispTime);
document.layers.pendule.document.close();
}
else
if (document.all)
pendule.innerHTML = dispTime;
setTimeout(“clock()”, 1000);
}
// End –>
</script>

<p><center><br>
<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>
by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 07.2003 — [font=monospace]<!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;

Date.ONE_DAY = Date.ONE_HOUR * 24;

Date.ONE_WEEK = Date.ONE_DAY *
7;

function TimeSince (d) {this.time = d.getTime ? d.getTime() : Date.parse(d)}

TimeSince.prototype.valueOf = function () {return new Date ().getTime() - this.time}

TimeSince.prototype.toString = function () {

var t = Math.abs(this.valueOf());

var d = Math.floor (t / Date.ONE_DAY);

var h = Math.floor ((t % Date.ONE_DAY) / Date.ONE_HOUR);

var m = Math.floor ((t % Date.ONE_HOUR) / Date.ONE_MINUTE);

var s = Math.floor ((t % Date.ONE_MINUTE) / Date.ONE_SECOND);

return (this.valueOf () < 0 ? '-' : '') + [d, d == 1 ? 'day' : 'days', [h, m < 10 ? '0' + m : m, s < 10 ? '0' + s : s].join(':')].join(' ');

}

var time = new TimeSince ('7 November 2003');

document.write('<p id="time">',time , '</p>');

if (document.getElementById) setInterval ("document.getElementById('time').firstChild.data = time",0.2 * Date.ONE_SECOND);

// -->

</script>[/font]
×

Success!

Help @NetTechie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...