Results 1 to 2 of 2
  1. #1
    bengregg is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default Can't Get Gregorian Calender to Work

    I'm trying to make an application which gives the date and weekday in 100 days and that also shows the weekday of my birthday and the date 10,000 days from my birthday, here is what I have...

    package GregorianClock;

    /**
    *
    * @author Ben
    */
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;

    public class MainClass {
    public static void main(String[] a) {
    GregorianCalendar cal = new GregorianCalendar();
    Date now = cal.getTime();
    System.out.println(now);

    int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
    int weekday = cal.get(Calendar.DAY_OF_WEEK);
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);

    cal.add(Calendar.DAY_OF_MONTH, 100);
    System.out.println("In 100 days the Date will be:" + month +"-"+ dayOfMonth +"-"+ year + " " + "And the Weekday will be" +" " +weekday);



    GregorianCalendar bday = new GregorianCalendar(1991, Calendar.JUNE, 21);

    int bdaydayOfMonth = bday.get(Calendar.DAY_OF_MONTH);
    int bdayweekday = bday.get(Calendar.DAY_OF_WEEK);
    int bdayyear = bday.get(Calendar.YEAR);
    int bdaymonth = bday.get(Calendar.MONTH);

    System.out.println("The Weekday of my Birthday is:" + bdayweekday);
    bday.add(Calendar.DAY_OF_MONTH, 10000);
    System.out.println("10000 Days after my Birthday is:" + bdaymonth + "-" + bdaydayOfMonth +"-"+ bdayyear);


    }
    }

    The program displays the current date and weekday and my current birthday instead of using the add function I give it to display new values. Any help is appreciated. Also for some reason it give me 5-21, 1991 for my birthday when June is the 6th month?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    You get the values for day, month etc before you add the 100 (or 10,000) days, so they show the original values.

Similar Threads

  1. Gregorian Calendar
    By bindhuuk4 in forum New To Java
    Replies: 1
    Last Post: 08-07-2009, 12:00 PM
  2. Calender
    By tiger100plus in forum New To Java
    Replies: 1
    Last Post: 12-26-2008, 07:20 PM
  3. date and calender not getting the right results
    By valoyivd in forum New To Java
    Replies: 4
    Last Post: 04-14-2008, 11:51 AM
  4. Help with gregorian calendar
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:21 PM
  5. Gregorian calendar issue
    By orchid in forum New To Java
    Replies: 1
    Last Post: 05-16-2007, 06:51 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
  •