Try this by noticing that the months start from zero, so we need to subtract them for the correct month:
Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month-1); calendar.set(Calendar.DATE, day); Date date = calendar.getTime();
Or that:
Calendar calendar = Calendar.getInstance(); calendar.set(year, month-1, day); Date date = calendar.getTime();
Or that:
Date date = new GregorianCalendar(year, month-1, day).getTime();
The first method gives you more control since it allows you to set other fields in the date, for example: DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, WEEK_OF_MONTH, WEEK_OF_YEAR, MILLISECOND, MINUTE, HOUR, HOUR_OF_DAY
Finally, to properly format the date specified in the comments, do the following:
DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); String strDate = df.format(date);
source share