views:

115

answers:

1

Hi, 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?

+3  A: 

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();
    }
}
Max Gontar
Thanks Max, It worked :)
imMobile
You welcome :)!
Max Gontar