barantes
asked on
GregorianCalendar add error
I would like to add a day to a date using GregorianCalendar but the add method ins't working properly ...
It add 12 hours to the date instead of a day ...
Please, take a look at the code bellow:
-------------------------- ---------- ---------- --------
GregorianCalendar calcDate = new GregorianCalendar();
// date is : Sat Oct 16 00:00:00 BRT 1993 and is a parameter
calcDate.setTime(date);
calcDate.add(Calendar.DAY_ OF_MONTH, 1);
calcDate.set(Calendar.HOUR , 0);
calcDate.set(Calendar.MINU TE, 0);
calcDate.set(Calendar.SECO ND, 0);
calcDate.set(Calendar.MILL ISECOND, 0);
log.debug("dateAdd Diary = " + date + " - " + calcDate.getTime());
-------------------------- ---------- ---------- ----------
It print's: dateAdd Diary = Sat Oct 16 00:00:00 BRT 1993 - Sat Oct 16 12:00:00 BRT 1993
The set method isn't working too...
Please, help me!
It add 12 hours to the date instead of a day ...
Please, take a look at the code bellow:
--------------------------
GregorianCalendar calcDate = new GregorianCalendar();
// date is : Sat Oct 16 00:00:00 BRT 1993 and is a parameter
calcDate.setTime(date);
calcDate.add(Calendar.DAY_
calcDate.set(Calendar.HOUR
calcDate.set(Calendar.MINU
calcDate.set(Calendar.SECO
calcDate.set(Calendar.MILL
log.debug("dateAdd Diary = " + date + " - " + calcDate.getTime());
--------------------------
It print's: dateAdd Diary = Sat Oct 16 00:00:00 BRT 1993 - Sat Oct 16 12:00:00 BRT 1993
The set method isn't working too...
Please, help me!
works fine here
works for me too, what version of java are you using?
java -version in your dos-prompt or unix-shell
java -version in your dos-prompt or unix-shell
Well,
Try to modify the format of your windows's date setting from Start>Control Panel>Regional Options.
Basically your codes should work fine as what objects said.
I hope that helps.
Try to modify the format of your windows's date setting from Start>Control Panel>Regional Options.
Basically your codes should work fine as what objects said.
I hope that helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
8-)