...

View Full Version : Simple Clock, but slowed down!



Carl_FK
10-23-2006, 07:32 PM
Hi guys,

I'm trying to achieve this, but don't know how to go about it:
All I need to do is write some javascript that displays a clock, in the format of HH:MM:SS that updates automatically every second. However, here's the twist:

I need this clock to start at 7AM and gradually work its way up to 3.30PM across a period of (approx) two actual weeks. So in reality, every second on this clock should take about 40 seconds in real life. Would you say that this is possible?
I wouldn't know where to start, so all help is greatly appreciated.

Note: it doesn't have to take exactly two weeks. Give or take several hours, I don't mind.

Many thanks!

Philip M
10-23-2006, 11:13 PM
You cannot do this reliably using JavaScript which is purely client-side. You need a server-side langauge such as PHP or PERL to keep track of your artificial "time".

jalarie
10-24-2006, 09:34 PM
Is this what you need?


<script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
CurrentTime='070000';
ST_delay=40000;
function DoTime() {
Now_S=CurrentTime%100; // seconds
Now_M=Math.floor(CurrentTime/100)%100; // minutes
Now_H=Math.floor(CurrentTime/10000); // hours
if (Now_S < 10) { Now_S='0'+Now_S; }
if (Now_M < 10) { Now_M='0'+Now_M; }
if (Now_H < 10) { Now_H='0'+Now_H; }
Output=Now_H+':'+Now_M+':'+Now_S;
ST=document.getElementById('SlowTime');
ST.innerHTML=Output;
ST_timeout=setTimeout("DoTime();",ST_delay);
Now_S++;
if (Now_S > 59) {
Now_M++;
Now_S=0;
}
if (Now_M > 59) {
Now_H++;
Now_M=0;
}
if (Now_H > 12) {
Now_H=1;
}
Now_S*=1;
Now_M*=1;
Now_H*=1;
if (Now_S < 10) { Now_S='0'+Now_S; }
if (Now_M < 10) { Now_M='0'+Now_M; }
if (Now_H < 10) { Now_H='0'+Now_H; }
CurrentTime=''+Now_H+Now_M+Now_S;
} // DoTime
// End hiding -->
</script>

The slow time is now
<span name="SlowTime" id="SlowTime">##:##:##</span>.

Philip M
10-24-2006, 10:48 PM
This only works for one browser session. Each time the user revisits the site the "slow clock" is re-set to 07:00:00.

A cookie could be used to keep track of the "time", but as I say this is not at all reliable as the cookie can be deleted (or altered) by the user. Or the user may not have JavaScript enabled, or may refuse to accept cookies ........

Carl_FK
10-25-2006, 05:49 PM
Thanks for the replies!
I'm a master at server-side codes, it's just the JS that I'm pretty weak on.

If you could possibly modify the code kindly provided by jalarie, and maybe put in caps TIME FROM SERVER-SIDE CODE or whatever is necessary :)

Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum