sorry if the title is confusing. Let me explain clearly. I need to play with days, months and years. In order to do this I use Calendar. Here is my code;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int dayStart=0,monthStart=0,yearStart=0,dayFinish=0,monthFinish=0,yearFinish=0;
Calendar cal = (Calendar) Calendar.getInstance();
cal.set(Calendar.MONTH,Calendar.MAY); //SET MONTH AS MAY
cal.set(Calendar.DATE,1);
cal.set(Calendar.YEAR,2018);
monthStart=(cal.getCalendar.MONTH)+1);
dayStart=cal.get(Calendar.DATE);
yearStart=cal.get(Calendar.YEAR);
System.out.println("STARTING DAY: "+dayStart+" STARTING MONTH: "+monthStart+" STARTING YEAR: "+yearStart);
cal.add(Calendar.MONTH,6); //ADD 6 MONTHS
monthFinish = (cal.get(Calendar.MONTH)+1);
dayFinish = (cal.get(Calendar.DATE));
yearFinish = (cal.get(Calendar.YEAR));
System.out.println("FINISHING DAY: "+dayFinish+" FINISHNG MONTH: "+monthFinish+" FINISHING YEAR: "+yearFinish);
//WHAT I WANT IS printing out the days between 2 dates: 184
}
First, I set the time: 1 5 2018, then I add 6 months and the time becomes 1 11 2018. I need to get day difference as 184 (If I set the month January, it should be 181) Is it possible to do it just converting the corresponding Calendar fields (date,month,year) to secs or milliseconds and subtract millisecond value of (1 5 2018) from the (1 11 2018) and convert back milliseconds to days? There are similar questions but I couldn't find the solution exactly in the way I want.