I want return today's date and plus the next 7 days. How could I manage this?
I mean if today's date is 31.07.2013 Wednesday I want it returns also 1.08.2013 Thursday and so on...
I want return today's date and plus the next 7 days. How could I manage this?
I mean if today's date is 31.07.2013 Wednesday I want it returns also 1.08.2013 Thursday and so on...
Try this
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());
I haven't tested it :)
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);
Output:
todaydate 2013-07-31 weekAfter 2013-08-06
Try something like this
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());