• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display difference between two timestamps in Hours

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
In my application i have two different dates for example
req_date: 2008-12-12 16:54:23
assigned_date: 2008-12-16 19:56:59
Here i want to display the difference between two timestamps in "Hours:minutes:seconds"
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the timestamps as Date objects, or as strings? If they are strings, then first use SimpleDateFormat to parse them into Date objects (see the API documentation of SimpleDateFormat for information on how to do that).

Then, call getTime() on both the Date objects and subtract the return values. This will give you the difference between the two timestamps in milliseconds. With some simple math you can compute how many hours, minutes and seconds that is.

Try writing some code that does what I described above, and if you get stuck, ask more questions here.
 
I am mighty! And this is a mighty small ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic