|
Hi everyone...
I have a doubt regarding the date in java.. i have to add two days with the present date. that is if the present date is '01/21/2006' and if we have to add 12 days then i should get '02/02/2006'.. i have tried one.. by taking the day part alone in the date and by adding.. but if we do like that then the result will be '01/33/2006' which is invalid. is there any other way????.....Pls help me to get thru this...
Thanks.
|
|
|
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class CalendarAddition {
public static void main(String[] args) {
DateFormat df = new SimpleDateFormat("M/dd/yyyy");
Calendar calendar = Calendar.getInstance();
// Set the date to 21 Jan 2006
calendar.set(2006, 0, 21);
Date start = calendar.getTime();
System.out.println("start = " + df.format(start));
// Add twelve days to start.
calendar.add(Calendar.DAY_OF_MONTH, 12);
Date twelveDaysLater = calendar.getTime();
System.out.println("later = " + df.format(twelveDaysLater));
}
}
|
|
|
|
|
|
|
|
|
|