-3

I have a assignment for a class where we take in a date then see if the date given is valid. If it is we then add a day onto it. Where I am having trouble is after I check that the date is valid it is saved to

Date appointment = new Date();

appointment = new Date(month, day, year);
Date.advanceDate(appointment);

in a different file called Date.java

public static void advanceDate(Date aDate){
    //here is where I need to read the date in aDate
}

After searching online through the Java api I haven't been able to find a way to add a day onto appointment or get the day, month, and year from appointment add a day to that and then save it as a new Date

what I have tried is doing after looking at http://docs.oracle.com/javase/8/docs/api/java/util/Date.html

aDate.getDay();

but eclipse tells me "the method getDate()is undefined for the type Data

aDate.toString();

this doesn't return the month date and year it returns its location in memery

every solution I've found online uses Calender which seems to have replaced Date

Bynienar
  • 3
  • 3
  • What API are you looking at? http://docs.oracle.com/javase/8/docs/api/java/util/Date.html – Sotirios Delimanolis Feb 08 '15 at 06:18
  • I looked at that API, maybe I was doing something wrong but what i tried was appointment.getDay(); then eclipse tells me the method getDay() is undefined for the type Data – Bynienar Feb 08 '15 at 06:33

1 Answers1

0

I believe you are looking for a Calendar and a DateFormat,

int year = 2015;
int month = Calendar.FEBRUARY; // <-- this is actually a 1.
int date = 8;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.set(year, month, date);
cal.add(Calendar.DAY_OF_MONTH, 1);
System.out.println(df.format(cal.getTime()));

Output is

2015-02-09

1FEBRUARY.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249