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:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java get Next Day
Post your Comment