-2

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...

  • You could just increment a date by one day 7 times: http://stackoverflow.com/questions/428918/how-can-i-increment-a-date-by-one-day-in-java – rebeliagamer Jul 31 '13 at 08:09

3 Answers3

0

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 :)

Yotam
  • 9,789
  • 13
  • 47
  • 68
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);

Output:

todaydate 2013-07-31 weekAfter 2013-08-06

Tanu Garg
  • 3,007
  • 4
  • 21
  • 29
0

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());
Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115