2013-07-31 32 views
-2

我希望返回今天的日期並加上接下來的7天。我怎麼能管理這個?如何返回本週的所有日期

我的意思是,如果今天的日期是2013年7月31日週三,我想這也是2013年8月1日返回週四等等...

+0

你可以只以一天7次遞增日期:http://stackoverflow.com/questions/428918/how-can-i-increment- java中的date-by-one-day – rebeliagamer

回答

0

嘗試是這樣的

Calendar today = Calendar.getInstance(); 
    System.out.println(today.getTime()); 
    today.add(Calendar.DATE,1); 
    System.out.println(today.getTime()); 
    today.add(Calendar.DATE,1); 
    System.out.println(today.getTime()); 
+0

@downvoter,請留意留言 –

0

試試這個

String date = (new Date()).toString(); // Start date 
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
Calendar c = Calendar.getInstance(); 
c.setTime(sdf.parse(date)); 
c.add(Calendar.DATE, 7); // number of days to add 
date = sdf.format(c.getTime()); 

我沒有測試它:)

+0

這是錯誤的,這會給今天7天后的日子 –

0
here is the code: 

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 

      Date date = new Date(); 
      String todaydate = dateFormat.format(date); 

      Calendar cal1 = Calendar.getInstance(); 
      cal1.add(Calendar.DATE, 6); 
      Date nextDate= cal1.getTime(); 

      String weekAfter = dateFormat.format(nextDate); 

      System.out.println("todaydate " + todaydate); 
      System.out.println("weekAfter " + weekAfter); 

輸出:

todaydate 2013年7月31日 weekAfter 2013 -08-06

+0

再次閱讀問題 –

+0

@ruchira提供了這個概念。不是勺子餵養。 –

相關問題