-2

I have two date in form as:

date1 = Tue Jan 01 00:00:00 NPT 2013
date2 =  Tue Sep 30 00:00:00 NPT 2014

Now I need to find the difference between these two dates.

How can I do this in Java or in Groovy.

injecteer
  • 20,038
  • 4
  • 45
  • 89
  • 2
    Did you do any research at all? Because if I paste your literal title into Google, it gives me useful results... – Ivar Jun 29 '16 at 08:50
  • Actually a duplicate of http://stackoverflow.com/questions/2755835/duration-between-two-dates-in-groovy badly tagged as Java – tim_yates Jun 29 '16 at 09:20

1 Answers1

2

Convert your dates to miliseconds and operate with them:

long diffInMills = date2.getTime() - date1.getTime();

in seconds

diffInMills / 1000 

in minutes

diffInMills / (1000*60)

in hours

diffInMills / (1000*60*60)

in days

diffInMills / (1000*60*60*24)
SCouto
  • 7,808
  • 5
  • 32
  • 49