I am trying to compare 2 calendar objects with their dates.
My code:
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.set(2017, 1,2);
c2.set(2017, 1,1);
int compared = c1.compareTo(c2);
textView.setText("" + compared);
The result should be an int of either -1 or 1, in which my case should be: -1.
However, this is not the result I want. I want to be able to compare dates directly say:
01/20/2010 compared to 02/30/2014 returns true or false.
Is there some ways to achieve this based on the Calendar lib?
I am aware of built in methods such as getDay(), getMonth(), equals() and so on. The problem is that in using getDay(), getMonth(), getYear(), it is very difficult to make a comparison as I'm comparing between 3 ints.
Also, I got a feeling that to compare between 2 dates, I will have to set the timezone and the timeinMillis to be the same. Meaning to compare the date direct, for cal1 and cal2, its time zone and timeinmillis has to be the same.
Can someone clarify this to me?