开发者

J2ME calendar add date problem

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 MIDletStateChangeEx开发者_开发知识库ception {
        // TODO Auto-generated method stub
            Calendar cal=Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DAY_OF_MONTH, -5);
    }

}


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));

?


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:

  • http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118

Specifically the Calendar class

An implementation of an "add date" method is described here:

  • http://tcstechies.wordpress.com/2008/09/10/date-add-in-midp-j2me-calendar/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜