Results 1 to 2 of 2

Thread: Help with dates

  1. #1
    bumblyb33 is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default Help with dates

    Hello,

    I need to enter a date and find out what day of the week that date will be on after N years. I need some help on where to get started. I've had a look at the Date, GregorianCalendar and Calendar classes but I don't know which ones to use..I feel lost. Any help would be appreciated.

    Bee

  2. #2
    l_m_b is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Default

    Dude, do not feel so lost :p Here is a sample starting point...

    Java Code:
    public class Test 
    {
    	public static void main(String args[])
    	{
    		printDay(new Date(), 5);
    	}
    	
    	private static void printDay(Date aDate, int years)
    	{
    		Calendar cal = Calendar.getInstance();
    		cal.setTime(aDate);
    		
    		cal.add(Calendar.YEAR, years);
    		switch(cal.get(Calendar.DAY_OF_WEEK))
    		{
    			case Calendar.MONDAY:
    				System.out.println("Monday");
    				break;
    			case Calendar.TUESDAY:
    				System.out.println("Tuesday");
    				break;
    			case Calendar.WEDNESDAY:
    				System.out.println("Wednesday");
    				break;
    			case Calendar.THURSDAY:
    				System.out.println("Thursday");
    				break;
    			case Calendar.FRIDAY:
    				System.out.println("Friday");
    				break;
    			case Calendar.SATURDAY:
    				System.out.println("Saturday");
    				break;
    			case Calendar.SUNDAY:
    				System.out.println("Sunday");
    				break;
    		}
    	}
    }

Similar Threads

  1. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 08:05 AM
  2. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:06 AM
  3. Comparing dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:02 AM
  4. Inbetween Dates
    By Rageagainst20 in forum New To Java
    Replies: 4
    Last Post: 12-19-2007, 06:24 AM
  5. differences between 2 dates
    By cecily in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 06:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •