-4

I need to calculate the number of days passed between 2 dates using java.util.Date, java.util.Calendar and java.text.SimpleDateFormat. I'm breaking my brain, how could I accomplish that?

dharam
  • 7,604
  • 15
  • 61
  • 90
OneMoreVladimir
  • 1,633
  • 3
  • 20
  • 31

1 Answers1

1

It seems like an interview question, similar was asked to me in an interview 2 months back.

Well, here is another hint: You have two dates. Java gives you time in millis for each date. Say t1 and t2.

Without loss of generality we can assume t1>t2. now t = t1-t2

divide t by 86400 * 1000 ( number of milliseconds in a day) and that is your answer :)

dharam
  • 7,604
  • 15
  • 61
  • 90