Count the time duration

Discussion in 'Java' started by rainny, Mar 23, 2009.

  1. rainny

    rainny Guest

    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.
     
    rainny, Mar 23, 2009
    #1
    1. Advertising

  2. rainny wrote:
    > 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

    --
    RGB
     
    RedGrittyBrick, Mar 23, 2009
    #2
    1. Advertising

  3. rainny

    Roedy Green Guest

    On Mon, 23 Mar 2009 01:49:48 -0700 (PDT), rainny <>
    wrote, quoted or indirectly quoted someone who 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.


    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
     
    Roedy Green, Mar 23, 2009
    #3
  4. rainny

    Daniel Pitts Guest

    Roedy Green wrote:
    > On Mon, 23 Mar 2009 01:49:48 -0700 (PDT), rainny <>
    > wrote, quoted or indirectly quoted someone who 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.

    >
    > 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.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, Mar 23, 2009
    #4
  5. rainny

    Guest

    On Mar 23, 4:49 am, rainny <> wrote:
    > 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.


    The Calendar class should be able to help you:
    http://java.sun.com/javase/6/docs/api/java/util/Calendar.html
     
    , Mar 23, 2009
    #5
  6. rainny

    Mayeul Guest

    wrote:
    > On Mar 23, 4:49 am, rainny <> wrote:
    >> 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.

    >
    > The Calendar class should be able to help you:
    > http://java.sun.com/javase/6/docs/api/java/util/Calendar.html


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

    --
    Mayeul
     
    Mayeul, Mar 23, 2009
    #6
  7. On Mon, 23 Mar 2009 19:47:46 +0100, Mayeul wrote:

    > wrote:
    >> On Mar 23, 4:49 am, rainny <> wrote:
    >>> 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.

    >>
    >> The Calendar class should be able to help you:
    >> http://java.sun.com/javase/6/docs/api/java/util/Calendar.html

    >
    > 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.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Mar 24, 2009
    #7
  8. rainny

    Steve Allen Guest

    Steve Allen, Mar 24, 2009
    #8
  9. rainny

    rainny Guest

    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
     
    rainny, Mar 24, 2009
    #9
  10. rainny

    Guest

    On Mar 24, 2:21 am, Steve Allen <> wrote:
    > The correct answer may depend on what country you live inhttp://www.ucolick.org/~sla/leapsecs/epochtime.html


    It may also depend on how fast you're going... will this app be used
    in a context that's moving at a significant fraction of c? :p
     
    , Mar 24, 2009
    #10
  11. rainny

    Guest

    On Mar 24, 1:00 pm, rainny <> wrote:
    > 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.
     
    , Mar 24, 2009
    #11
  12. rainny

    Steve Allen Guest

    On Mar 24, 10:30 am, wrote:
    > It may also depend on how fast you're going...


    In that case it can depend on whether you take your kids on a weekend
    jaunt up to camp out on a mountain
    http://www.leapsecond.com/great2005/index.htm
    (well, you'd need to spend all summer up there to accumulate a
    millisecond)
     
    Steve Allen, Mar 24, 2009
    #12
  13. rainny

    Lew Guest

    rainny wrote:
    >> 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.


    wrote:
    > 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.

    --
    Lew
     
    Lew, Mar 25, 2009
    #13
  14. rainny

    Guest

    On Mar 25, 9:17 am, Lew <> wrote:
    > rainny wrote:
    > >> 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.

    > wrote:
    > > 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.
    >
    > --
    > Lew


    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...
     
    , Mar 25, 2009
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CJ
    Replies:
    2
    Views:
    604
  2. Rgemini
    Replies:
    0
    Views:
    350
    Rgemini
    Sep 14, 2004
  3. Dmitry Borisov

    Re: avi file duration, frame-count etc

    Dmitry Borisov, Sep 14, 2004, in forum: Python
    Replies:
    1
    Views:
    426
    Rgemini
    Sep 14, 2004
  4. Replies:
    9
    Views:
    402
  5. dave
    Replies:
    3
    Views:
    559
    Gabriel Genellina
    Jun 5, 2010
Loading...

Share This Page