Differential between two dates shown in hours

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Raul Araya
    New Member
    • Aug 2006
    • 2

    #1

    Differential between two dates shown in hours

    I got a requierement in which i need from a date to obtain a specific amount of hours passed, please tell me how to transform the differencial between two dates and translate it into an amount of hours.

    Greetings.
    Raul Araya.
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    You should consult this thread. It has a whole bunch of questions about date.
    Code:
    // Date d;
    // const int SECS_PER_MIN = 60;
    // const int MIN_PER_HR = 60;
    long hours = (d.getTime() / (SECS_PER_MIN * MIN_PER_HR))
    Date.getTime() returns how many seconds have passed since 1/1/1979. So that equation just converts it to hours. You never specify a reference point, you may need to add or subtract a fixed amount of hours.

    Comment

    Working...