"evolver";p="17860" wrote:57 replies for a countdown block, whaw...
I have been watching this topic with interest, but I see you struggling with the timezones...
Very logical, if you are using PHP to read the time because PHP doesn't read the usertime, only the servertime.
So the only way to get it right for every user by PHP would be by timezonecalculation for every user...
All this is unnecessary...
Javascript is better for this situation, and I use one...
Different from PHP, javascript will use the visitors computertime instead of servertime...
No need for special formulas to make it suitable with different timezones, and it will save your server some processing too...
...and with no extra tables to add in your database...
Can't be more easy than this:
Just make a block with HTML and place this code in it:
(It's javascript, so I've placed it as a downloadable compressed textfile)
The only problem would be language, if you have more languages on your forum.
This is a great idea just a question though.....
In the script it has the following.
- Code: Select all
countdownTo=new Date(31-12-2006);countdownTo.setYear(2006);countdownTo.setMonth(12);countdownTo.setDate(02);countdownTo.setHours(00);countdownTo.setMinutes(00);countdownTo.setSeconds(0);
This will give us a countdown till the new year but why is the date set to "02" I have replaced it with "31" which is the date I want it to countdown to and it then shows the wrong time left.
I have done a little research and come up with the following.
Be wary of the month input for your Date definition, however, as the Date object uses month values of 0 to 11 and not 1 to 12 as you may be used to.
So if we take this into consideration and set the month to "0" for January and the date to "01" then the countdown also shows the correct time left.
So with this it would be better to use the correct date and just always remember to -1 form the month you are counting down to.
This would then give us....
- Code: Select all
countdownTo=new Date(01-01-2007);countdownTo.setYear(2007);countdownTo.setMonth(0);countdownTo.setDate(01);countdownTo.setHours(00);countdownTo.setMinutes(00);countdownTo.setSeconds(0);
Have I got this correct or am I completely off track here <img>