Results 1 to 4 of 4

Thread: How to get next day in java?

  1. #1
    Join Date
    Jul 2009
    Posts
    1,179

    How to get next day in java?

    hi,

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

    Thanks

  2. #2
    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());
    }
    }

  3. #3
    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]);
        }
    }

  4. #4
    Join Date
    Jul 2009
    Posts
    1,179

    Re: How to get next day in java?

    Thanks for the quick reply

    I really needed the code for my friends website.

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. Java Programming using Adventnet SNMP Java API
    By ROCKING_Suhas in forum Software Development
    Replies: 5
    Last Post: 17-07-2010, 06:52 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,063,411.44170 seconds with 16 queries