1

I am looking for to calculate the time difference between two calendar dates and need the result difference in minutes. Below is what I am trying but it says: can't apply - operator. My page.getLastModified().getTime() gives me Calendar object. Any idea how can I achieve this.

long lastModified = page.getLastModified().getTime() - Calendar.getInstance().getTime();

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vivek Dhiman
  • 1,967
  • 6
  • 46
  • 82

2 Answers2

3

getTime() returns Date instance and there is no overloaded - operator for Date. You may try with getTimeInMillis() to get difference milliseconds between two dates. You can later convert these milliseconds to minutes for instance with

TimeUnit.MILLISECONDS.toMinutes(durationInMillis)
Pshemo
  • 122,468
  • 25
  • 185
  • 269
-1

I generally make use of

Joda Time

Simply because it has functions to give you the time between two dates.

Read into this previous post Usage for more info on how to.

Community
  • 1
  • 1
Koen Demonie
  • 539
  • 1
  • 7
  • 24