PYRO 912 PYRO 912 - 28 days ago 9
Java Question

declaring a startdate & endate using joda time?

I've already imported the joda libary and I was able to import the Easy Reader class. However, I need help formatting correctly so I can calculate the days in between, and yes, I am aquainted with the MM/dd/yyyy, but I've used integers. Do I need to import anything else? I'm really new at joda, so please be patient, thanks. Everything seems to work fine, but I cant find the right syntax that will help me find the difference between the two dates, and I can't find it.

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
class starter{
public static void BdayPrgm(String args[]){

System.out.println("Please Enter Today's Month: ");
EasyReader month = new EasyReader();
//this will indentify it as an INT, not a string.
//quest is a question btw.
todaysmon = month.readInt();

System.out.println("What number is today?: ");
EasyReader currentday = new EasyReader();
todayday = currentday.readInt();



System.out.println("What is today's year?: ");
EasyReader todayyear = new EasyReader();
year = todayyear.readInt();

System.out.println("");

System.out.println("What is your BdayMonth?: ");
EasyReader thatyear = new EasyReader();
bdaymon = thatyear.readInt();

System.out.println("What is your Bday #?: ");
EasyReader thatday = new EasyReader();
thatgr8day = thatday.readInt();

System.out.println("What is the bdayyear?: ");
EasyReader bdayyear = new EasyReader();
bdayyr = bdayyear.readInt();


int age;
age = year - bdayyr;


//we can get start date by putting test maybe?
DateTimeZone LA = DateTimeZone.forID("America/Los_Angeles");
LocalDate start = new LocalDate(year,todaysmon,todayday);
LocalDate end = new LocalDate(year,bdaymon,thatgr8day);

int Days;
//code isn't compileing below. I don't know what I'm doing wrong.
Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays();

//int days = d.getdays;

System.out.println("");

System.out.println(CELEB1+" is going to be "+age+" years old in X days!");


}

}

Answer Source

This

int Days;
Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays();

should be something like

int dayCount = Days.daysBetween(start, end).getDays();

Because start and end are already LocalDate(s) and you want to save the result of the call. Also, you should only need one EasyReader instance. And, you'll need to add

import org.joda.time.Days;