Results 1 to 1 of 1
  1. #1
    Sturm is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default GregorianCalendar help

    Hello, I'm in serious need of help with my program using GregorianCalendar.

    I need to find the difference between two dates in months. I've googled for it and haven't found anything but I did find this forum. So here's what I've been using to get the difference and print the result.

    Java Code:
    System.out.println("Number of months between your birthday and this date: " +
        		Math.abs(((otherDate.get(Calendar.YEAR)-birthDate.get(Calendar.YEAR))*12)+(otherDate.get(Calendar.MONTH)-birthDate.get(Calendar.MONTH))));
    However, the Teacher's Aide teaching my class told me there's a simpler way to do this. I can't find it, so any help is appreciated...

    Edit: Solved the next part, so I'll post how. Just need a better way to calculate difference.

    Also, is there a way to get the system date using only the GregorianCalendar and not Date?
    Yes,
    Java Code:
    GregorianCalendar currentDate  = new GregorianCalendar();
    Thanks.
    -Sturm
    Last edited by Sturm; 02-03-2010 at 10:02 PM.

Similar Threads

  1. Problem with "GregorianCalendar"
    By tola.ch2004 in forum New To Java
    Replies: 2
    Last Post: 07-12-2007, 08:12 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
  •