Re: Month difference between dates
- From: CodeForTea@xxxxxxxxx
- Date: 30 Mar 2007 14:17:17 -0700
On Mar 30, 4:33 pm, "zamba" <CRISTIAN_FERR...@xxxxxxxxxxx> wrote:
Hi i want to know if there is a way to know exactly the number of
months (instead o days) between to diferent dates..
Thanks a lot
Calendar calendar1 = new GregorianCalendar();
Date trialTime = new Date();
calendar1.setTime(trialTime);
int month1 = calendar1.get(Calendar.MONTH);
Date monthAhead = new Date();
Calendar calendar2 = new GregorianCalendar();
calendar2.setTime(monthAhead);
calendar2.roll(Calendar.MONTH, 8);
int month2 = calendar2.get(Calendar.MONTH);
System.out.println("Month 1 = " + month1 );
System.out.println("Month 2 = " + month2 );
Month 1 = 2
Month 2 = 10
Once you have the months from both dates, you can manipulate them.
Dinesh
.
- Prev by Date: Re: Month difference between dates
- Next by Date: Re: Sound recording applet ;-)
- Previous by thread: Re: Month difference between dates
- Next by thread: Networking works from computer A to computer B, but not vice versa ?!?
- Index(es):