0

I want to get the date interval for each month in a given month.I have three Edit Text .I have enter date in 1st EditText and i have enter 30 days in 2nd Edit Text and I want to display that date after 30 days in 3rd Edit Text. After that 30 days it should be display in 3rd Edit Text date in 1st EditText.Can someone help me please. Thanks to appreciate. Like 1 Oct -> 1 Nov, 2 Nov -> 1 dec, 2 dec -> 1 jan, 2 Jan -> 1 feb

Here is my Activity Code

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.form_details);


        // Get current date by calender
            final Calendar c = Calendar.getInstance();
            year  = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day   = c.get(Calendar.DAY_OF_MONTH);


         etReplacementDate.setText(new StringBuilder()
            // Month is 0 based, just add 1
            .append(month + 1).append("-").append(day).append("-")
            .append(year).append(" "));



         etInterval_Date.setText(new StringBuilder()
            // Month is 0 based, just add 1
            .append(month + 1).append("-").append(day).append("-")
            .append(year).append(" "));



         etReplacementDate.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                showDialog(DATE_OF_REPLACEMENT);
            }
        });


         etInterval_Date.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                showDialog(DATE_OF_INTERVAL);
            }
        });


    @Override 
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_OF_REPLACEMENT:

            return new DatePickerDialog(this, pickerListenerReplacement, year, month, day);

        case DATE_OF_INTERVAL:

            return new DatePickerDialog(this, pickerListenerInterval, year, month, day);

        }
        return null;
    }


     private DatePickerDialog.OnDateSetListener pickerListenerReplacement = new DatePickerDialog.OnDateSetListener() {

            // when dialog box is closed, below method will be called.
            @Override
            public void onDateSet(DatePicker view, int selectedYear,
                    int selectedMonth, int selectedDay) {

                year  = selectedYear;
                month = selectedMonth;
                day   = selectedDay;

                // Show selected date 
                etReplacementDate.setText(new StringBuilder().append(month + 1)
                        .append("-").append(day).append("-").append(year)
                        .append(" "));

               }
            };



            private DatePickerDialog.OnDateSetListener pickerListenerInterval = new DatePickerDialog.OnDateSetListener() {

                // when dialog box is closed, below method will be called.
                @Override
                public void onDateSet(DatePicker view, int selectedYear,
                        int selectedMonth, int selectedDay) {

                    year  = selectedYear;
                    month = selectedMonth;
                    day   = selectedDay;

                    // Show selected date 
                    etInterval_Date.setText(new StringBuilder().append(month + 1)
                            .append("-").append(day).append("-").append(year)
                            .append(" "));

                   }
                };


}
Robotics
  • 129
  • 13
  • possible duplicate of [Add 30 days to Date in java](http://stackoverflow.com/questions/11727933/add-30-days-to-date-in-java) – Basil Bourque Aug 13 '14 at 09:22

2 Answers2

1

Add days to the calendar. Use the following code, For more information refer this link

      Calendar cal = Calendar.getInstance()

      // print current date
      System.out.println("The current date is : " + cal.getTime());

      // add 30 days to the calendar
      cal.add(Calendar.DATE, 30);
      System.out.println("30 days later: " + cal.getTime());


      // add 60 days to the calendar
      cal.add(Calendar.DATE, 30); // already 30 days added
      System.out.println("60 days later: " + cal.getTime());
Finder
  • 1,217
  • 5
  • 18
  • 46
0

Use GregorianCalendar For Adding Specified Dates In Calender..

Calendar cal=new GregorianCalendar();

    //added 30 days from currunt date
    cal.add(Calendar.DATE, 30);
    Date dte =cal.getTime(); //getting new date
Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40