Reputation: 21076
I'm using eclipse pulsar under java vm 1.6 . the problem is java.util Calendar
class add method raises an error "The method add(int, int) is undefined for the type Calendar" but its fine as per the documentation.
package caltest;
import java.util.Calendar;
import java.util.Date;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class caltest extends MIDlet {
public caltest() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
Calendar cal=Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, -5);
}
}
Upvotes: 1
Views: 2127
Reputation: 34294
How about this?
// Subtract 5 days from the time in the calendar object
cal.setTime(new Date(cal.getTime().getTime() - 5 * 86400000));
or
// Subtract 5 days from "now" and set it in the calendar object
cal.setTime(new Date((new Date()).getTime() - 5 * 86400000));
?
Upvotes: 6
Reputation: 421330
You say that you're using Java 1.6, but is that for your project or merely for running Eclipse?
If the project you're working on is running with the J2ME runtime, you should be looking at the documentation here:
Specifically the Calendar
class
An implementation of an "add date" method is described here:
Upvotes: 3