PDA

View Full Version : countdown between two dates using JavaScript


John V
05-14-2003, 04:00 PM
I have an auction software that currently displays when an auction will close in this format: 05/21/2003 23:18

I would like to display additionally, a countdown in this format:

2 days, 6 hours, 25 minutes, 54 seconds

However, I need to use the hosting server's time not the user's computer time since the user's computer will not be synchronized to the host server's time.

I have seen a lot of javascripts for countdowns, but they all are using the computer time of the user so I have not been able to use these scripts for the purpose I intend.

I can get the server time including seconds when the webpage is served.

Is there a countdown scripit available that would allow me to define the close time and the server time
for example:

closetime=06/21/2003 23:18:00
servertime=06/19/2003 07:16:31

(or I can manipulate to whatever time format is most appropriate)

then have the script countdown in seconds between these two times?

By counting down using the server time instead of the user's time there is no chance that the auction item will close before or after the user thinks it will. You know how some folks like to wait till the last minute (second) to place a bid.

Any help would be appreciated, thanks

John V

Danne
05-14-2003, 10:14 PM
If you use ASP and JScript as Serverside-language, you could probably do something like this:


var serverDate=new Date("<%=new Date()%>");


But considering the download time, this will not be accurate. Maybe you can do a function to synchronize it...

John V
05-15-2003, 12:46 AM
Thanks for the input.

I can get the server time and only need to access that time reference once before the countdown script begins. After the countdown has begun, I no longer need to check the time on the server as clcok time should wind down on both the server and the user's computer with little or no variation.

If there is any difference in the countdown zero'ing out and the server reaching closing time, it (hopefully) will be one to two seconds depending on how fast the webpage served up the time variable and that variable was passed to the countdown javascript.


John V