• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Problem

 
Rajul King
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Daniel, it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic