Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 3
Trades: 0
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
 
 
Register now for full access!
Old 12-26-2008, 04:01 PM Re: JS Time difference problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,516
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.codingforums.com/showthread.php?p=744750
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Closed Thread     « Reply to JS Time difference problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.41523 seconds with 12 queries