回答
嘗試是這樣的
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());
@downvoter,請留意留言 –
試試這個
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());
我沒有測試它:)
這是錯誤的,這會給今天7天后的日子 –
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
再次閱讀問題 –
@ruchira提供了這個概念。不是勺子餵養。 –
- 1. 如果日期是一個月的開始,獲取本週的所有日期返回不正確
- 2. 日期/ gmdate返回錯誤的週數
- 3. 如何在本週和下週檢索所有包含日期的行? SQL Server
- 4. MySQL日期大於返回所有行
- 5. 如何返回給定日期的一週正確的日期 - 年月和
- 6. 根據日期返回週數
- 7. 從上週末返回日期
- 8. 返回多個日期範圍之間的所有日期
- 9. 下週末的日期時間在JavaScript返回無效日期
- 10. SQLite返回記錄日期超過一週的日期
- 11. 如何日期值分配給所有返回的MySQL查詢
- 12. 如何返回兩個日期之間的週末日期列表
- 13. jQuery的日期選擇器返回週一至週五只
- 14. 如何返回日期值
- 15. 查詢返回輸入日期和三週前返回
- 16. 本週星期一日期
- 17. 如何在SQL中獲取當年的所有周末日期?
- 18. MySQL:如何使用當前日期獲取「本週的日期」?
- 19. 如何獲取本週的開始日期和結束日期?
- 20. 出發日期和返回日期的數據框,如何獲取所有日期的列表?
- 21. 從LibGit2Sharp返回特定日期以來的所有git日誌
- 22. 如何獲取本週的所有日期時間實例,給定一天?
- 23. 獲得了週一和週二的所有日期爲明年
- 24. 現有腳本循環日期,周,月,年的日期範圍?
- 25. 返回日期,如果日期範圍
- 26. 選擇生日在本週(週一至週日)的所有用戶
- 27. 如果特定日期的日期沒有值,則返回0
- 28. 如何在任何給定的日期在本週獲得週末日?
- 29. 如何僞造java.time.LocalDate返回的日期?
- 30. SQL:如何獲取周開始日期和周結束日期
你可以只以一天7次遞增日期:http://stackoverflow.com/questions/428918/how-can-i-increment- java中的date-by-one-day – rebeliagamer