Or using Java 1.8 (which has zero-based year, and one-based months and days): Date result = Date.from(LocalDate.of(year + 1900, month + 1, day).atStartOfDay(ZoneId.systemDefault()).toInstant()); Here are equal versions of Date, Calendar, and Java 1.8: This line day_month = month_day[1] * userMonth + userDay; is always using 29 as month_day[1] is always referring to February. Also if it is not mandatory to do the calculations yourself look at the suggested API`s as they give you much better functionality. A month is represented by an integer from 0 to 11; 0 is January, 1 is February, and so forth; thus 11 is December. A date (day of month) is represented by an integer from 1 to 31 in the usual manner. An hour is represented by an integer from 0 to 23. Thus, the hour from midnight to 1 a.m. is hour 0, and the hour from noon to 1 p.m. is hour 12. In Java 8 (better because it avoids any implicit reference to system timezone): public static boolean isLastDayOfMonth (int year, int month, int day) { LocalDate date = LocalDate.of (year, month, day); return date.lengthOfMonth () == day; } The Java 8 solution is very clearly to be preferred. When this answer was written 8 years ago, Java 8 was First you should to get the first day from date from your input year and month 2017/February; Second you should to get the number of days of this month; Third you should to loop until the number to your days in your case from 1 to 28 and add a day to your date Either get year, month and day from your date-time using methods getYear, getMonthValue and getDayOfMonth. Or use formatters to get these as strings rather than ints. I would prefer to have two-digit names for all month and date folders (09 for September and 02 for the 2nd of the month). In some cases this will help you get the correct h99ZG.

java date year month day