Java - Write code to get Date Of Month

Requirements

Write code to get Date Of Month

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(getDateOfMonth(startDate));
  }//from  w w  w .  j  a  va 2  s. c o  m

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

Related Exercise