How to determine tomorrow's date in J2ME for use in a DateField?

匆匆过客 提交于 2019-12-24 19:08:10

问题


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:


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



回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/757583/how-to-determine-tomorrows-date-in-j2me-for-use-in-a-datefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!