posted 18 years ago
Checking the number of milliseconds between the two dates runs into problems when the dates are close to 5 yrs apart, because the number of milliseconds in 5 yrs depends on how many leap years are included.
A better approach is to subtract 5 years from the current date, and then compare the result to the other date (which Calendar.compareTo does by comparing milliseconds).
BTW, have you clearly defined the boundary? Is it based on date and time, or just date? For example, a date and time comparison makes 2pm Jan 10 2000 more than 5 years before 3pm Jan 10 1005, but in many real-world applications (like have you owned a car for more than 5 years) you need to go back to Jan 9 2000 before you are considered to be more than 5 years before Jan 10 2005.