add and sub datefrom current date
int monthsToAdd = 4;
int monthsToSubtract = 10;
Calendar c = Calendar.getInstance();
System.out.println("Current date : " + (c.get(Calendar.MONTH) + 1) +
"-" + c.get(Calendar.DATE) + "-" + c.get(Calendar.YEAR));
// add months to current date
c.add(Calendar.MONTH, monthsToAdd);
System.out.println("Date (after): " + (c.get(Calendar.MONTH) + 1) +
"-" + c.get(Calendar.DATE) + "-" + c.get(Calendar.YEAR));
c = Calendar.getInstance();
// sub months to current date
c.add(Calendar.MONTH, -monthsToSubtract);
System.out.println("Date (before): " + (c.get(Calendar.MONTH) + 1) +
"-" + c.get(Calendar.DATE) + "-" + c.get(Calendar.YEAR));
Comments
Post a Comment