Once you have the number of days as difference / 86400000, then the remainder (which you want to break down into hours and so on) is difference % 86400000.
However you have a completely different error, namely assuming that each day is 24 hours. That isn't the case in many places. For example where I live we have daylight saving time, so one day in the spring has only 23 hours and one day in the autumn has 25 hours. If you don't care about that then carry on with your calculation. If you do care about it (and you probably should for real-life applications) then you need to let the Calendar class take care of those details. Something like this:
Find the TimeUnit enumerated type in the standard Java API, and read about that. It might help change milliseconds to days, etc. It might also have constants like MILLISECONDS_IN_DAY. I am not sure; I haven't used it for a long time.
The difference in milliseconds is difference % MILLISECONDS_IN_SECOND The difference in seconds is difference % MILLISECONDS_IN_MINUTE / SECONDS_IN_MINUTE. etc etc. Just beware: you might get very strange results with the % operator if the original argument is negative!
Joined: Oct 13, 2005
Paul Clapham and I seem to agree about the % operator and nothing else. Just goes to show there are usually several equally valid ways to do anything on a computer.