0

I am doing an android project and I have 2 date objects

  1. Fri Apr 17 00:00:00 GMT+05:30 2015
  2. Thu Apr 16 21:12:27 GMT+05:30 2015

Here difference b/w these 2 dates is not 24 hrs, but as the day changes from Thu to Fri I need the difference as 1.

Please help..

user2085965
  • 393
  • 2
  • 13
  • 33
  • How do you want to handle DST changes? If you don't care about those, and you're really just interested in view 1 day == 24 hours, then you can just call `getTime()` on each `Date`, subtract one value from the other, and divide by the number of milliseconds in a day. – Jon Skeet Apr 16 '15 at 15:50
  • @JonSkeet I think he wants the answer to be 1 day, if the difference was less than 24 hours but the start date was the day before. – Sanj Apr 16 '15 at 15:58
  • @JonSkeet: Exactly. you got my requirement. Please help if you have answer or share related links. – user2085965 Apr 16 '15 at 16:03
  • @user2085965: I've already given you a suggestion *and* closed the question as the duplicate of another... – Jon Skeet Apr 16 '15 at 16:09
  • @JonSkeet: let me confirm, Joda Time is your recommended solution.? – user2085965 Apr 16 '15 at 16:16
  • @user2085965: Yes, I'd use Joda Time. You need to consider what time zone you want. I'd convert the `Instant` to a `DateTime`, then take the `LocalDate` from that, then use `Period` to find the number of days. – Jon Skeet Apr 16 '15 at 16:34

0 Answers0