Home Java Java-get-example Java get Next Day
Questions:Ask|Latest


 
 

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

Liked it!  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.

Posted on: November 1, 2008

Ask Questions?    Discuss: Java get Next Day  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com