|
I have the following method in my class: private int newDate(int date, int increment, int targetYear) { int retdate = 0; if (date > 0) { int year = date / 10000; int month = (date - (year * 10000)) / 100; int day = date - ((year * 10000) + (month * 100)); year = targetYear; Calendar cal = new GregorianCalendar(year, month, day); cal.add(Calendar.DATE, increment); year = cal.get(Calendar.YEAR); month = cal.get(Calendar.MONTH); day = cal.get(Calendar.DAY_OF_MONTH); retdate = (year * 10000) + (month * 100) + day; } return retdate; } It should take the date and decrease by the amount of the increment using the targetYear as the year of the date instead. Here's the problem. I sent it the following parms: date = 20050502; increment = -2, targetYear = 2007. When it gets to the cal.add(Calendar.DATE, increment) the value of the date is 2007/05/02 and I want to decrease it by 2. It returns 2007/04/31 wtf? There is no such date. Is this an issue with the calendar class? Thanks, Ron Power Programmer Information Services City Of St. John's, NL P.O. Box 908 St. John's, NL A1C 5M2 709-576-8132 rpower@xxxxxxxxxx http://www.stjohns.ca/ ___________________________________________________________________________ Success is going from failure to failure without a loss of enthusiasm. - Sir Winston Churchill
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.