Get Days Till End Of Year in Java

Description

The following code shows how to get Days Till End Of Year.

Example


//from  w  w w . j ava2  s . c om
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {

  public static void main(String args[]) {

    Calendar calendar1 = Calendar.getInstance();
    int currentDayOfYear = calendar1.get(Calendar.DAY_OF_YEAR);

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

    Calendar calendar2 = new GregorianCalendar(year, 11, 31);
    int dayDecember31 = calendar2.get(Calendar.DAY_OF_YEAR);

    int days = dayDecember31 - currentDayOfYear;
    System.out.println(days + " days remain in current year");
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone