Java Calendar get day of year

Description

Java Calendar get day of year

import java.util.Calendar;

public class Main {

  public static void main(String[] args) {
    Calendar gCal = Calendar.getInstance();

    int dayOfYear = gCal.get(Calendar.DAY_OF_YEAR);
    System.out.println(dayOfYear);

    // Print the number of days left in the year
    System.out.println("Days left in year: " + (365 - dayOfYear));

  }/*from  w  ww.j av a2  s.co  m*/
}



PreviousNext

Related