Results 1 to 1 of 1
Thread: GregorianCalendar help
- 02-03-2010, 10:43 PM #1Member
- Join Date
- Feb 2010
- Rep Power
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.
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))));
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?
GregorianCalendar currentDate = new GregorianCalendar();
Last edited by Sturm; 02-03-2010 at 11:02 PM.
- By tola.ch2004 in forum New To JavaReplies: 2Last Post: 07-12-2007, 08:12 PM