time calculations

Please support our JavaScript / DHTML / AJAX advertiser: 50% Off 6 Months Web Hosting from 1&1. The World's #1 Host!
Reply

Join Date: Oct 2007
Posts: 3
Reputation: shemayb is an unknown quantity at this point 
Solved Threads: 0
shemayb's Avatar
shemayb shemayb is offline Offline
Newbie Poster

time calculations

 
0
  #1
Oct 1st, 2007
How can I get the difference of two time values using javascript?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,768
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 493
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: time calculations

 
0
  #2
Oct 2nd, 2007
Take a look at the functions provided by the Date object of Javascript and try your own hand at it. Post your attempt with the problems you are facing if you are stuck.
I don't accept change; I don't deserve to live.

Sacrifice is a painful, pure and beautiful thing.

Dammit, Jones, What the Hell Are Knoll Pointers?!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 3
Reputation: shemayb is an unknown quantity at this point 
Solved Threads: 0
shemayb's Avatar
shemayb shemayb is offline Offline
Newbie Poster

Re: time calculations

 
0
  #3
Oct 2nd, 2007
i tried using the parse method but it didn't work.My case is this: i have a time in and a time out, i want to subtract my time out to my time in so that i can get the total difference of the two.Only time,it does not include the date.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,768
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 493
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: time calculations

 
0
  #4
Oct 2nd, 2007
It depends a lot on the format in which the times are expressed. Post some code so that we have something to chew on.
I don't accept change; I don't deserve to live.

Sacrifice is a painful, pure and beautiful thing.

Dammit, Jones, What the Hell Are Knoll Pointers?!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 3
Reputation: shemayb is an unknown quantity at this point 
Solved Threads: 0
shemayb's Avatar
shemayb shemayb is offline Offline
Newbie Poster

Re: time calculations

 
0
  #5
Oct 2nd, 2007
here is my sample code:

var end =Date.parse(etime);
var start=Date.parse(stime);

var total =(end-start);
if (total > 2)

{
//alert message here
}
else
{
//link here
}
-Smi=>e
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,266
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 170
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: time calculations

 
0
  #6
Oct 7th, 2007
Several questions:

1. What format are the variables "etime" and "stime" in?

2. What do you want the value "2" to represent? It's not seconds or days. It is supposed to be milliseconds, but some implementations use jiffies instead (multiples of the Intel 55 ms interrupt period).

3. What units did you expect "total" to be in? You don't have any guarantee of what unit of measure the variable "total" is in. It is an internal time unit that depends on the computer used.

4. Do you really want to measure 2 ms times? Windows computers can't measure such times without special hardware.

Note that the system clock does not update each millisecond. Usually the system clock is updated once every 55ms jiffy. If you are really trying to measure intervals of 2 ms, you are doomed to failure. I/O itself happens only once every 55 ms on Windows computers.

DOS computers could do this. Windows computers can't.

One thing you could do is make a standard for comparison:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. std = knownEndTime - knownStartTime; // set a standard time interval for your comparison.
  3. diffo = end - start;
  4.  
  5. if (diffo > std) {
  6.  
  7. // code for diffo is greater than the standard interval
  8.  
  9. }
  10. else {
  11.  
  12. // code for diffo is less than or equal to the standard interval
  13.  
  14. }
Last edited by MidiMagic; Oct 7th, 2007 at 1:24 am.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2094 | Replies: 5
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC