|
Hi guys,
I'm developing a browser-based game which requires a javascript countdown.
I have one that works perfectly almost all the time, but I and several players have noticed times when it fails.
I think I have isolated the problem to midnight shifting. I have the following code, which generates the time difference between two dates in seconds:
Code:
date1 = (new Date(8, 10, 31, 20, 55, 0)).getTime();
date2 = (new Date(8, 10, 31, 23, 59, 0)).getTime();
Time_Left = Math.round((date2 - date1) / 1000);
alert(date2 + " - " + date1 + " = " + Time_Left);
This works fine. However, if I change date1 and date2 to i.e.
Code:
date1 = (new Date(8, 10, 31, 23, 55, 25)).getTime();
date2 = (new Date(8, 11, 1, 23, 59, 0)).getTime();
Time_Left will be a negative number even though it should be positive. I'm sure it's something really simple, but I can't see what. Anyone spot the problem?
Thanks
|