1

I'm trying to subtract today's date from another date in another year. I can't seem to change the year and the date at the same time for the set date I need to count how many days until.

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Wateber {

  public static void main(String args[]) {
     int summer = 2016;
    Calendar calendar1 = Calendar.getInstance();
    int currentDayOfYear = calendar1.get(Calendar.DAY_OF_YEAR);

    int year = calendar1.get(Calendar.YEAR);

    Calendar calendar2 = new GregorianCalendar(year, 6, 10);
    int dayJune10 = calendar2.get(Calendar.DAY_OF_YEAR);

    int remainingdays = 0;
    if (summer == 2016)
    {
        remainingdays = calendar2 - currentDayOfYear;
    }

    System.out.println(remainingdays + " days until summer");

        }
}
HelpMe
  • 61
  • 1
  • 8

0 Answers0