A little side project I've been doing for fun involves subtracting the current date from a future date given by the user to return the days between them.
public int getDaysBetween(int date2)
{
//Subtract current date from future date (date2), leaving the number of days between them
int getDaysBetween = 0;
Calendar myCalendar = Calendar.getInstance();
myCalendar.get(Calendar.DAY_OF_YEAR);
getDaysBetween = date2-Calendar.DAY_OF_YEAR;
return getDaysBetween;
}
The method for doing this is non-static, as the date2
int changes. However, when I try to reference it in my main class...
//Figure out a non-static reference
int date2 = Integer.parseInt(JOptionPane.showInputDialog("Enter a day in the year ahead of today"));
message = "Days bewteen: " + Date.getDaysBetween(date2-Calendar.DAY_OF_YEAR);
JOptionPane.showMessageDialog(null, message);
I get the error that a non-static method cannot be referenced from a static context.
I am fairly new to Java, so it might seem easy to most of you guys, but I could use the help.
Thanks in advance!