• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference in days between two days  RSS feed

 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to find out number of days elapsed between two days. I know that if hours elapsed between two days is above 24, its the next day. But this is not always the case for e.g.

02-19-2014 17:30:00 PM and 02-20-1014 13:15:00 PM

In the above case hour difference is <24.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not really the difference in hours between days, it's the difference in hours between two points in time. Are those points in time always in the same time zone? If so, using the methods in java.util.Date would work, otherwise you'll need to resort to java.util.Calendar. Calendar also respects DST, just in case that ever figures into the calculation (Date does not).
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:How to find out number of days elapsed between two days. I know that if hours elapsed between two days is above 24, its the next day. But this is not always the case for e.g.

So in fact, it's not really to do with the number of days elapsed. It's to do with the difference between calendar days. Indeed, as Ulf said, if the two time zones are different you could actually have two dates, d1 and d2, where d1 > d2, but shows the previous day when converted to a clock time.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!