我想返回今天的日期以及接下来的 7 天。我怎么能管理这个?
我的意思是如果今天的日期是 31.07.2013 星期三,我希望它也返回 1.08.2013 星期四,依此类推......
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);
输出:
今天日期 2013-07-31 周后 2013-08-06
尝试这个
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());
我还没有测试过:)
尝试这样的事情
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());