Reputation: 3617
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?
Upvotes: 1
Views: 544
Reputation: 22775
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();
}
}
Upvotes: 3