String to date and calculate the end of period

Well, I get back a date of the beginning of period
and I should calculate the date of the end of period.

First problem, the date of the beginning is a string. So, it is necessary to convert to Date object.
Second problem, I should calculate the date of the end.
Ex: date at the beginning of 2002-02-01 then the date of the end will be 2003-01-31).

But I don't know how to make!
Thank you for his help!
Who is Participating?
objectsConnect With a Mentor Commented:
Try something like:

SimpleDataFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d = df.parse(input);
Calendar c = Calendar.getInstance();
c.add(field, period);
String output = df.format(c.getTime());
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.