开发者

Add single unit of time to timestamp for use in Blackberry application

How can I add a single开发者_运维知识库 unit of time to timestamp, just like "add method" of Java "Calendar" class but by using Blackberry API set Can anyone please help me with source code?


You still can use Calendar in BlackBerry:

class Scr extends MainScreen {
    public Scr() {
        Date date = new Date(System.currentTimeMillis());
        add(new LabelField("now:"));
        add(new LabelField(date.toString()));
        add(new LabelField("past month:"));
        add(new LabelField(addDateTime(date, Calendar.MONTH, 1).toString()));
    }

    public Date addDateTime(Date date, int field, int addValue) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int value = c.get(field);
        c.set(field, value + addValue);
        return c.getTime();
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜