The line of code you have provided is a DateFormat
object that takes a date and formats it into a string representation. It doesn't have any actual data stored in it. You want to make a comparison on the actual date object, not the formatter.
There are a few different ways to store time, but a common way to store timestamps is as a Long
. Since longs are numbers, you can do comparison and math just like an Int
:
Long startTime = System.currentTimeMillis();
// Do some long task here that we want to know the duration of
Long endTime = System.currentTimeMillis();
Long difference = endTime - startTime;
Alternatively, there are libraries and tools for dealing with structured time data that may have other ways of storing timestamps and comparing them, however this is a quick example of a common simple implementation if you just need to quickly compare two timestamps.