2

假设今天是任意一天,我正在尝试找到下周二的日期。目前我只能找到本周星期二的日期......

cal.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);

我怎样才能得到下周二而忘记上周二?

4

2 回答 2

1

怎么样...

cal.set( Calendar.DAY_OF_WEEK, Calendar.TUESDAY );
cal.add( Calendar.DATE, 7 );

通常,这类问题会导致一群人理所当然地大喊“ JODA!”


[由 bwoogie 编辑] 我的最终代码:

Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);


        if(c.getTimeInMillis() < System.currentTimeMillis()) {
            c.add(Calendar.DATE, 7);
        }
于 2012-09-28T01:49:01.047 回答
0

试试这个

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
calendar.add(Calendar.DAY_OF_WEEK, 7);

SimpleDateFormat f = new SimpleDateFormat("MM/d/yyyy");

Log.d("Next", f.format(cal.getTime()));
于 2012-09-28T01:50:15.377 回答