• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

String to date and calculate the end of period

Hello!
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!
Ankou
0
ldanet
Asked:
ldanet
  • 2
1 Solution
 
objectsCommented:
Try something like:

SimpleDataFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d = df.parse(input);
Calendar c = Calendar.getInstance();
c.setTime(d);
c.add(field, period);
String output = df.format(c.getTime());
0
 
objectsCommented:
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now