androiddateandroid-calendar

how to get current date and 7thday from current day in android? and I want to show the dates in below format given by the image


In the given image first date is current date with month and day. and another date is 7th day from current date.

enter image description here

I tried with the below code::

 Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
            SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd.MM.yyyy");

            for (int i = 0; i < 7; i++) {
                Log.i("dateTag", sdf.format(cal.getTime()));
                cal.add(Calendar.DAY_OF_WEEK, 1);
            }
        tvDate1=(TextView) findViewById(R.id.calender_view1);
        tvDate1.setText("" + DateFormat.format("dd/MM/yyyy", System.currentTimeMillis()));


tvDate2=(TextView) findViewById(R.id.calender_view2);
        tvDate2.setText("here want to print 7thday");

Solution

  • SimpleDateFormat dateFormat= new SimpleDateFormat("EEEE dd.MM.yyyy");
    Calendar currentCal = Calendar.getInstance();
    String currentdate=dateFormat.format(currentCal.getTime());
    currentCal.add(Calendar.DATE, 7); 
    String toDate=dateFormat.format(currentCal.getTime());