Count the time duration

R

rainny

Hi, does anyone know how to calculate the time duration among two
columns? For example, column A have a.time whereas column B have
b.time. I want to calculate the difference of time between two
columns?

*besides, the time is calculated in milliseconds.

Thanks.
 
R

RedGrittyBrick

rainny said:
Hi, does anyone know how to calculate the time duration among two
columns? For example, column A have a.time whereas column B have
b.time. I want to calculate the difference of time between two
columns?

*besides, the time is calculated in milliseconds.

That is a very vague description. Are those columns in a database, in a
JTable or elsewhere? what is the data type of a.time and b.time?

http://mindprod.com/jgloss/time.html
http://mindprod.com/jgloss/calendar.html
 
R

Roedy Green

Hi, does anyone know how to calculate the time duration among two
columns? For example, column A have a.time whereas column B have
b.time. I want to calculate the difference of time between two
columns?

*besides, the time is calculated in milliseconds.

there is nothing to it. Just subtract.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Nature provides a free lunch, but only if we control our appetites."
~ William Ruckelshaus, America’s first head of the EPA
 
D

Daniel Pitts

Roedy said:
there is nothing to it. Just subtract.
In practice, that is what happens a lot.

Unfortunately duration has a lot of meanings that are not all compatible.

If you have May 5th, 2009 12:01pm and June 5th 2009 12:01pm, you might
want to say that the difference is one of:
a) 1 month.
b) 4 weeks and 3 days, a.k.a 31 days
c) epoch time A minus epoch time B.
d) the number of actual milliseconds between those times, which may
not actually be epoch time A minus epoch time B. (a day is only close to
24 hours, not exactly 24 hours)

(a) and (b) are easy to calculate using the Calendar class. (c) is easy
to calculate with either Date or Calendar. (d) is much more involved,
and depending on the situation may be affected by relativity theory.
 
M

Martin Gregorie

For calculating duration between two times? Can Calendar really help?

Depends what sort of time it is, what degree of accuracy he wants and how
long the time intervals are that he wants to measure: all unspecified by
the OP. Consider these possibilities:

- is it TAI?
- what about UTC, in which case you'd best know about leap seconds.
- or does it involve national systems which use daylight saving time?
- how about calculating time differences across time zones?
- now add in times that span midnight (or whenever your timezone decides
is 00:00:00).

Of all these, only the first can be done by simple subtraction and only
then if you're working with a time specified as the offset since a base
point, e.g. microseconds since midnight on the 31st of December 1899.

For everything else its easier to use the Calendar class.
 
R

rainny

Thanks for all the reply. I want to count the time is inside one
column. Such like the time is all sort in one column. Can i count the
duration time between the first row and second row? And then, display
the duration into another column? The column here is means that is
inside the JTable. But, the time is extracted out from database.

Thanks if anyone can help.

Regards
Rainny
 
L

lord.zoltar

Thanks for all the reply. I want to count the time is inside one
column. Such like the time is all sort in one column. Can i count the
duration time between the first row and second row? And then, display
the duration into another column? The column here is means that is
inside the JTable. But, the time is extracted out from database.

Thanks if anyone can help.

Regards
Rainny

Ok so it sounds like you want to get the difference between the
millisecond value in Row 1 and the millisecond value in Row 2... and
display it in ... a third column?
Yeah this shouldn't be too hard: when you are processing rows from
your dataset, always keep track of the previous row's millisecond time
value. That way you can always get the difference and display it where
ever you want... assuming I understood you correctly.
 
L

Lew

rainny said:
Thanks for all the reply. I want to count the time is inside one
column. Such like the time is all sort in one column. Can i [sic] count the
duration time between the first row and second row? And then, display
the duration into another column? The column here is means that is
inside the JTable. But, the time is extracted out from database.

Ok so it sounds like you want to get the difference between the
millisecond value in Row 1 and the millisecond value in Row 2... and
display it in ... a third column?
Yeah this shouldn't be too hard: when you are processing rows from
your dataset, always keep track of the previous row's millisecond time
value. That way you can always get the difference and display it where
ever you want... assuming I understood you correctly.

The concept of "previous" and "next" rows doesn't exist in the database; it
depends entirely on the sort order imposed by the query.
 
L

lord.zoltar

rainny said:
Thanks for all the reply. I want to count the time is inside one
column. Such like the time is all sort in one column. Can i [sic] count the
duration time between the first row and second row? And then, display
the duration into another column? The column here is means that is
inside the JTable. But, the time is extracted out from database.
Ok so it sounds like you want to get the difference between the
millisecond value in Row 1 and the millisecond value in Row 2... and
display it in ... a third column?
Yeah this shouldn't be too hard: when you are processing rows from
your dataset, always keep track of the previous row's millisecond time
value. That way you can always get the difference and display it where
ever you want... assuming I understood you correctly.

The concept of "previous" and "next" rows doesn't exist in the database; it
depends entirely on the sort order imposed by the query.

heh yeah... I had assumed that if he already had them in some sort of
display widget (or was able to get them there) there was already some
sort of sort order. I don't know much else about the context so....
*shrug*... I guess you could also try and do this directly in the
query, depending on the data...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top