Home Java Java-get-example Java get Next Day



Java get Next Day
Posted on: November 1, 2008 at 12:00 AM
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.

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

Related Tags for Java get Next Day:
javacclasscalendariogetusingthisstudytoexteilsectionincalasnextcajndaclendhowdaysisllarxtvassthavstndono


More Tutorials from this section

Ask Questions?    Discuss: Java get Next Day  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

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.