Java Date get Month int value, January starting from 0

Requirements

Write code to get Date Of Month

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  www. j a  va 2s .  c o  m

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



PreviousNext

Related