我试图从另一年的另一个日期中减去今天的日期。我似乎无法在设定的日期同时更改年份和日期,我需要计算多少天。
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");
}
}