Java Calendar get from Year Month Day

Description

Java Calendar get from Year Month Day

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

public class Main {
  public static void main(String[] argv) {
    int year = 2020;
    int month = 2;
    int day = 4;//from w  ww. ja va2  s .  c om
    System.out.println(setYearMonthDay(year, month, day));
  }

  public static Date setYearMonthDay(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);
    return cal.getTime();
  }
}



PreviousNext

Related