Closed Thread
JS Time difference problem
Old 12-26-2008, 02:33 PM JS Time difference problem
Banned

Posts: 3
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
khanshab is offline
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-26-2008, 03:01 PM Re: JS Time difference problem
chrishirst's Avatar
Super Moderator

Posts: 19,022
Location: Blackpool. UK
http://www.codingforums.com/showthread.php?p=744750
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
View Public Profile Visit chrishirst's homepage!
 
Closed Thread     « Reply to JS Time difference problem
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.07691 seconds with 12 queries