Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-08-2009
Member
 
Join Date: Jul 2009
Posts: 1,174
How to get next day in java?

hi,

How to get next day in java?
Can some one please let me know?

Thanks
Reply With Quote
  #2  
Old 03-08-2009
Member
 
Join Date: Apr 2008
Posts: 44
Re: How to get next day in java?

Try this code:

Code:
import java.util.Calendar;

public class Days {

public static void main(String[] argv) {
Calendar origDay = Calendar.getInstance();
System.out.println ("Original Date: " + origDay.getTime());

Calendar prevDay = (Calendar) origDay.clone();
prevDay.add (Calendar.DAY_OF_YEAR, -1);
System.out.println ("Previous Day: " + prevDay.getTime());

Calendar nextDay = (Calendar) origDay.clone();
nextDay.add (Calendar.DAY_OF_YEAR, 1);
System.out.println ("Next Day: " + nextDay.getTime());
}
}
Reply With Quote
  #3  
Old 03-08-2009
Member
 
Join Date: May 2008
Posts: 29
Re: How to get next day in java?

Use 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, use the Calendar class.

Code:
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.
Code:

Code:
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]);
    }
}
Reply With Quote
  #4  
Old 03-08-2009
Member
 
Join Date: Jul 2009
Posts: 1,174
Re: How to get next day in java?

Thanks for the quick reply

I really needed the code for my friends website.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to get next day in java?"
Thread Thread Starter Forum Replies Last Post
Java Auto Updater wants me to update java everyday in Windows 7 minajoh Windows Software 4 04-09-2013 11:04 PM
Setting Of Java to The Point At Manual Java winni Software Development 4 10-01-2011 10:05 PM
Java Programming using Adventnet SNMP Java API ROCKING_Suhas Software Development 5 17-07-2010 06:52 AM
Link List Example in Java Sample program in Java trickson Software Development 2 04-08-2009 08:23 PM


All times are GMT +5.5. The time now is 01:22 PM.