• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display difference between two timestamps in Hours  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!