0

I'm having issues using a for loop to increment a SimpleDate with the current date to a date in the future using just days.

I first get my DAYS in a double eventDay variable, which is returned from public double getEventDays(). I'm trying to GRAB this variable, and use it in another public data access-er called public SimpleDate getEventDate()

First off I have no idea how to grab a variable from another data access-er, or if it's even possible. But even after that I need to initialize a for loop that will essentially be something like;

for (int 1 = 0, i < (int)eventDay, i+=1)
{
     eventDay.nextDay(); // need to use the .nextDay() to add a day N amount of times
     return eventDay;
}
return null;

I know this is completely wrong, but it's what I'm basically looking for, I just have no idea how to start it off.

Jay Kominek
  • 8,674
  • 1
  • 34
  • 51
Morgan Smith
  • 37
  • 1
  • 3
  • 6
  • Either use the Java 8 Time API or Joda-Time. Something like [this](http://stackoverflow.com/questions/21842934/how-to-add-days-to-java-simple-date-format/21842959#21842959) for example – MadProgrammer May 14 '15 at 21:49
  • Well this isn't what I was looking for exactly, I have to use a for loop and use the nextDay method from SimpleDate API to up the day of a SimpleDate by N amount. It's for School or else I'd try using the Java 8 Time API... – Morgan Smith May 14 '15 at 21:58
  • Yes, put the code inside a loop and pass it the value instead of the absolute value... – MadProgrammer May 14 '15 at 22:02

1 Answers1

0

Does this do what you want?

public SimpleDateFormat getEventDate() {
    final SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.getCalendar().add(Calendar.DAY_OF_MONTH, (int)getEventDays());
    return sdf;
}
cybersam
  • 63,203
  • 6
  • 53
  • 76