views:

512

answers:

3

I basically want to be able to show tomorrows date

I have this which shows today date

private Date date = new Date();

i tried this but this gave me jan 1 1970

private Date date = new Date(+1);

please help

+1  A: 

Note, the Date.setBlah and Date.getBlah methods are deprecated, Calendar should be used instead. (Not sure if that's available in J2ME though.)

private Date date = new Date();
date.setDate(date.getDate() + 1);
Ben S
class Date has been deprecated for years now, I don't think there's the risk of it disappearing over night... but you're right, Calendar is better written and should usually be used.
Yuval
To be totally fair, java.util.Date is not deprecated, just the methods for treating a Date as a collection of fields.
Ian McLaird
True, updated my post to reflect this.
Ben S
A: 

As suggested here, use an implementation of class Calendar like thus:

Calendar myCalendar = Calendar.getInstance();
long tomorrow = myCalendar.getTimeInMillis() + 24 * 60 * 60 * 1000;
myCalendar.setTimeInMillis(tomorrow);

And do whatever you want with that...

Hope this helps,

Yuval =8-)

Yuval
Why make your own Calendar implementation? Why not just use Calendar.getInstance() ?
Ian McLaird
Why indeed? must have been the late hour that made me forget about getInstance. noted and edited.
Yuval
+5  A: 

The integer (actually long) parameter for the Date constructor is for specifying the milliseconds of offset from January 1st, 1970, GMT.

You need to use a Calendar instead

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
Date date = cal.getTime();
Ian McLaird