• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

compute duration in seconds

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following information:
IntervalStartDate: '2008-09-18'
IntervalStartTime: '17.48.33'
IntervalEndDate: '2008-09-19'
IntervalEndTime: '18.18.33'

I would like to compute duration of interval in seconds.

Can anyone suggest an easy way to do this (an open source object library?)?
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about concatenating the date and time strings, parse it to a date object, with the SimpleDateFormat class. Then take the difference of the two times from the date objects, and divide by 1000 to convert the interval from milliseconds to seconds?

Henry
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry's onto a winner there, but if you really must have an API just for this I suggest Joda Time.
Its very handy but for what you described its overkill and will take you longer to download, add to classpath, read the docs to understand how to use it to solve your particular problem and then write the code.

With Henry's solution you can skip the docs except to check input perhaps, Sun's javadocs also often have useful snippets of code so you can solve this one in a couple of minutes using standard API.
 
reply
    Bookmark Topic Watch Topic
  • New Topic