File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Date Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Date Problem" Watch "Date Problem" New topic

Date Problem

Rajul King
Ranch Hand

Joined: Apr 12, 2001
Posts: 47
i am using the calendar class to display the date on my JSP; i am rolling my day back by one day by using the command
if (true){
cal.roll(Calendar.DATE, false);
now, it is rolling only the date but not the month and this is creating descrepencies;
Condition 1: when the date is not the first day of the month, this method works perfect;
Condition 2: when the date is the first day of the month, it rolls the day back only the date by one day but does not change the month; for example: when it is May 1,2001 it shows rolled back date as May 31, 2001 instead of April 30,2001;
any help will be appreciated.
Daniel Bernier

Joined: May 15, 2001
Posts: 2
Perhaps it's a bit of a hack, but you could check the date, and if it's the first, do some kind of manual rollback.
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
why don't you use: add(Calendar.DATE, 1).
the doc says: roll(f, delta) adds delta to field f without changing larger fields.
Rajul King
Ranch Hand

Joined: Apr 12, 2001
Posts: 47
Thanks Daniel, it worked.
I agree. Here's the link:
subject: Date Problem
It's not a secret anymore!