Solved: Javascript Date

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

cpscdave

Thread Starter
Joined
Feb 25, 2004
Messages
445
Hi everyone

We have a little javascript function that gives a countdown
Code:
<script type="text/javascript">

var now = new Date();
var event = new Date("<?=$lookout_expiry?>");
var time_left = (event - now) / 1000;
var minutes = Math.floor(time_left / 60);
var seconds = Math.floor(time_left % 60);


ID=window.setTimeout("update();", 1000);
function update() {
now = new Date();
 time_left = (event - now) / 1000;
 minutes = Math.floor(time_left / 60);
 seconds = Math.floor(time_left % 60);

//seconds = (event - now) / 1000;
//seconds = Math.round(seconds);
//minutes = seconds / 60;
//minutes = Math.round(minutes);
document.counter.minutes.value = minutes;
document.counter.seconds.value = seconds;
ID=window.setTimeout("update();",1000);
}
</script>
The code worked great except on the live server which is 1 hour behind us in time, the countdown is off by 1 hour!
Is there an easy fix for this?
 

cpscdave

Thread Starter
Joined
Feb 25, 2004
Messages
445
Found a work around.
This works cause in this cause I always know how long the countdown needs to be

Code:
<script type="text/javascript">


var time_left = 300; 
var minutes = Math.floor(time_left / 60);
var seconds = Math.floor(time_left % 60);


ID=window.setTimeout("update();", 1000);

function update() {
    if ( typeof update.counter == 'undefined' ) {
        // It has not... perform the initilization
        update.counter = 0;
    }

update.counter+=1;


 time_left = 300 - update.counter;
 if(time_left <0){
   time_left = 0; }
 minutes = Math.floor(time_left / 60);
 seconds = Math.floor(time_left % 60);

//seconds = (event - now) / 1000;
//seconds = Math.round(seconds);
//minutes = seconds / 60;
//minutes = Math.round(minutes);
document.counter.minutes.value = minutes;
document.counter.seconds.value = seconds;
ID=window.setTimeout("update();",1000);
}
</script>
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top