Solved

String to date and calculate the end of period

Posted on 2002-06-18
2
204 Views
Last Modified: 2010-04-01
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
Comment
Question by:ldanet
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 7086611
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
 
LVL 92

Expert Comment

by:objects
ID: 7086755
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with Pie chart in Jsp 20 215
getting Http 404 error in jsp forms 8 79
SimpleDateFormat.parse examples 19 93
difference between projection and projection list in hibernate 1 108
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question