Share on Google+Share on Google+

Java get Next Day

Advertisement
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

Advertisements

Posted on: November 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java get Next Day  

Post your Comment


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