How to get tomorrow's date or future day?
I use the Calendar class to calculate with dates.
eg:
?
class Main { public static void main(String[] args) { Date now = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(now); cal.add(Calendar.DAY_OF_YEAR, 1); }}?
?
eg:
?
?
GregorianCalendar calendar = new GregorianCalendar();//Display the date now:Date now = calendar.getTime();DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, Locale.UK);String formattedDate = fmt.format(now);System.out.println(formattedDate);//Advance the calendar one day:calendar.add(calendar.DAY_OF_MONTH, 1);Date tomorrow = calendar.getTime();formattedDate = fmt.format(tomorrow);System.out.println(formattedDate);//Advance the calendar 30 more days:calendar.add(calendar.DAY_OF_MONTH, 30);Date futureDay = calendar.getTime();formattedDate = fmt.format(futureDay);System.out.println(formattedDate);?
?
eg:
?
?
GregorianCalendar calendar = new GregorianCalendar();calendar.add(calendar.DAY_OF_MONTH, 0);System.out.println(new SimpleDateFormat("dd/MM/yyyy").format((Date) calendar.getTime()));?
?
?
eg:
?
?
public String getDate(Integer getDay) {GregorianCalendar calendar = new GregorianCalendar();calendar.add(Calendar.DAY_OF_MONTH, getDay);return new SimpleDateFormat("dd/MM/yyyy") .format((Date)calendar.getTime());}?
?
?
?
?
?
?
?