Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Retrieving a particular date through simple arithmati

  Asked By: Boell    Date: Jul 31    Category: Java    Views: 1032

I need to go back say a week from a particular date eg. need to go
back a week from today (i.e. to find date of a week ago) taking into
consideration any start day of months like eg 1 Jan.
I tried using this piece of code but i was being given an error:

Calendar now = Calendar.getInstance();
int nowdate= now.get(Calendar.DATE);
add(nowdate, -7);

When i printed nowdate i was getting this error (This was actually a
jsp file & all relevant jsp tags were in place with the above piece
of code):
Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server
Error) that prevented it from fulfilling this request.
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred between lines: 55 and 56 in the jsp
file: /adminconsoletest.jsp
Generated servlet error:
\work\Standalone\localhost\_\adminconsoletest$jsp.java:90: Method add
(int, int) not found in class org.apache.jsp.adminconsoletest$jsp.
add(nowdate, 7);
Note: C:\jakarta-tomcat-4.0.4
\work\Standalone\localhost\_\adminconsoletest$jsp.java uses or
overrides a deprecated API. Recompile with "-deprecation" for
1 error, 1 warning



1 Answer Found

Answer #1    Answered By: Hubba Akhtar     Answered On: Jul 31

Remember everything in Java is a class

Calendar now = Calendar.getInstance();
now.add( Calendar.DATE, -7 );

This should give you the result.

Didn't find what you were looking for? Find more on Retrieving a particular date through simple arithmati Or get search suggestion and latest updates.