Solved

String to date and calculate the end of period

Posted on 2002-06-18
2
202 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now