user13644242 wrote:Why should there be such a method on DateFormat? DateFormats job is to parse and format dates, it does no calculations on it.
Thanks for your reply.
But I couldnt find any method that will return the date incremented by 1
user13644242 wrote:You know what? You need to look at the API.
Can anyone please help me how to convert the date in GregorianCalendar to Date object ... ?
user13644242 wrote:You're doing it wrong. Really, horribly, criminally wrong. You ignored my advice. You're making it much harder than it has to be, and now your code is brittle.
Thanks Everyone for your Help
I finally managed to write the following piece of code
Integer year=new Integer(startDateStr.substring(7));
the above piece is working. But it looks like un optimized code.Optimization has nothing to do with it. That code just plain sucks out loud without a clue. It's awful.
Can any one please help me optimize the above code in terms of performanceWhy? You ignored the good advice we've already given you. Why should we waste more time giving you more advice you'll just ignore?
YoungWinston wrote:It's so much fun talking to a brick wall, isn't it?
You know what? You need to look at the API.
What do you think a method that converts a GregorianCalendar to a Date is going to look like? What is it going to return?
Once you've found a method that matches (and read its documentation ), then do as jverd suggests and look at SimpleDateFormat. And read its documentation too.
Just read API of SimpleDateFormat + Calendar.
final String startDate = "30-MAR-2011"; // define the date format mask (note: my default locale does not parse MAR to 03, so I pass US locale) final SimpleDateFormat formatter = new SimpleDateFormat( "dd-MMM-yyyy", Locale.US ); // convert string to date final Date dateObject = formatter.parse( startDate ); // set calendar to prefered date final Calendar cal = Calendar.getInstance(); cal.setTime( dateObject ); // add one month cal.add( Calendar.MONTH, 1 ); System.out.println( cal.getTime() );