Java get Next Day

In this section, you will study how to get the next day in java using Calendar class.

Java get Next Day

In this section, you will study how to get the next day in java using Calendar class.

Java get Next Day

Java get Next Day

     

In this section, you will study how to get the next day in java using Calendar class.

In the given example, we have used the class DateFormatSymbols in order to get the names of the days of the week. The method getWeekdays() provide the string of days of week. To get the current day, we have used the Calendar class.

cal.get(Calendar.DAY_OF_WEEK)- This will return the current day.

cal.get(Calendar.DAY_OF_WEEK)+1- This will return the next day.

Here is the code of GetNextDay.java

import java.util.Calendar;
import java.text.*;

public class GetNextDay {
    public static void main(String[] args) {
      String dayNames[] = new DateFormatSymbols().getWeekdays();
      Calendar cal = Calendar.getInstance();
      System.out.println("Today is " + dayNames[cal.get(Calendar.DAY_OF_WEEK)]);
      System.out.println("Tomorrow is a " + dayNames[cal.get(Calendar.DAY_OF_WEEK)+1]);
    }
}

Output will be displayed as:

Download Source Code