I am trying to compare two dates. My first date is:
Date previousDate ="Returns a date as 2011-12-09 in a gregorian date"
and the second date is my “current date”, where I am getting my current date as:
SimpleDateFormat format = new SimpleDateFormat("yyyy/mm/dd");
Date date=new Date();
When I am try to compare the current date with my previous date, I am only able to compare the year (or only the first thing in the pattern).
System.out.println("date"+previousDate.compareto(format(date));
I am able to get the out put as “1”, as it is only comparing the year but not whole date.
Can any of you guys figure out what i am missing.I tried many approaches but couldn’t succeed.please let me know if i can work out with this or i need a different solution.
Thanks.
By
I guess you mean
But the important point is that by convention
compareTousually returns -1, 0 or 1.Here’s the implementation of Date#compareTo :