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?
I need to calculate the number of days passed between 2 dates using java.util.Date,
Share
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 🙂