• Post Reply Bookmark Topic Watch Topic
  • New Topic

add a day to the date  RSS feed

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a string containing date in 'dd-MON-YYYY' format. I need to add 1 (one)day to the value of 'dd' in the above string.

For ex: if the date i have is '29-FEB-2004', I need to add one day and the final date in String format should be '01-MAR-2004'.

Thanks,
Sreeni
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can code like this:

import java.util.*;
...
Date dd = new Date(aYear,aMonth,aDay);
GregorianCalendar cc = new GregorianCalendar();
cc.setTime(dd);
cc.add(Calendar.DAY_OF_YEAE,1);
dd = cc.getTime();

// now,the dd was added one day!
 
Chao Yuchen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cc.add(Calendar.DAY_OF_YEAE,1);

// sorry, it should be cc.add(Calendar.DAY_OF_YEAR,1);
~~~~pay attention here
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sreeni, you might like to take a look at the java.util.Calendar class documentation.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I second Dirk's recommendation.

Modifying Chao Yuchen's example, what you can do, more succinctly and more accurately is the following:

Jules
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!