Java - Write code to get Date Of Year

Requirements

Write code to get Date Of Year

Demo

import java.util.Calendar;
import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    Date startDate = new Date();
    System.out.println(getDateOfYear(startDate));
  }//  ww w  .j a  v a2s . c  o  m

  public static int getDateOfYear(Date startDate) {
    Calendar cc = Calendar.getInstance();
    if (startDate != null) {
      cc.setTime(startDate);
    }
    return cc.get(Calendar.YEAR);
  }
}

Related Exercise