Search code examples
androidandroid-2.2-froyo

Android Date: finding future date


I am looking and have been looking for a good example or tutorial on calculating/finding a future date by adding a set number of days.

I have a date picker that opens when user clicks on EditText so they can select the date, then I'm wanting to add lets say 56 days to that date. then show a Toast or Dialog that displays the future date from the date set. Then after i learn and figure that out I'm going to have my app show a notification on that date.

not sure if i should be using calendar or alarm,, oh and this data is being stored in a SQLite DB. like always hope i have given enough info to give you an idea of what I'm trying to do.

any help, pointers or suggestions will be awesome, as i am still learning both java and android


Solution

  • public void getFutureDate(Date currentDate, int days) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(currentDate);
        cal.add(Calendar.DATE, days);
    
        Date futureDate = cal.getTime();
    }
    

    currentDate: Date from date picker, days: Number of days to be added to currentDate

    Hope this would help.