importjava.text.DateFormat;importjava.text.SimpleDateFormat;importjava.util.Calendar;publicclassTest{publicstaticvoidmain(String[]args)throwsException{DateFormatdateFormat=newSimpleDateFormat("yyyy-MMM-dd");Calendarcalendar=Calendar.getInstance();calendar.add(Calendar.DATE,-1);System.out.println(calendar.getTime());// Tue Aug 31 09:56:28 IST 2021dateFormat.format(calendar.getTime());// Change format as per "yyyy-MMM-dd"}}
importjava.util.Calendar;publicclassTest{publicstaticvoidmain(String[]args)throwsException{Calendarcalendar=Calendar.getInstance();calendar.add(Calendar.HOUR,-24);System.out.println(calendar.getTime());// Tue Aug 31 11:08:25 IST 2021Calendarcalendar2=Calendar.getInstance();calendar2.add(Calendar.DAY_OF_MONTH,-1);calendar2.getTime();System.out.println(calendar.getTime());// Tue Aug 31 11:08:25 IST 2021}}
importjava.util.Calendar;publicclassTest{publicstaticvoidmain(String[]args)throwsException{Calendarcalendar=Calendar.getInstance();calendar.add(Calendar.HOUR,+24);System.out.println(calendar.getTime());// Tue Aug 31 11:08:25 IST 2021Calendarcalendar2=Calendar.getInstance();calendar2.add(Calendar.DAY_OF_MONTH,+1);calendar2.getTime();System.out.println(calendar.getTime());// Tue Aug 31 11:08:25 IST 2021}}