import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
public class CheckIn{
Date today;
void getArrivalDate() {
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try {
System.out.print("Enter Date in dd/mm/yyyy format: ");
String d = Keyboard.readString();
today = df.parse(d);
df.format(today);
} catch (ParseException e) {
e.printStackTrace();
}
}
void getDepartureDate(){
Calendar ca1 = Calendar.getInstance();
ca1.setTime(today);
System.out.print("How many nights do you want to stay? ");
int nights = Keyboard.readInt();
ca1.add(Calendar.DATE, nights);
System.out.println((ca1.get(Calendar.DATE))
+ "/"
+ ca1.get(Calendar.MONTH + 1)
+ "/"
+ ca1.get(Calendar.YEAR));
}
}
When I'm testing the method getDepartureDate(), the month isn't working well.
Eg. If I input 12/12/2011(Arrival Date) I get 14/50/2011 as a Departure Date.
I really can't understand this(Beginner)