We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Because months are zero indexed so Jan is 0, Feb is 1, etc. The input for month is the number format we recognize (Jan is 1, Feb is 2, etc.). Subtracting 1 from the input will give the correct value to set the Calendar month:
Input: month = 1 (for Jan)
Calendar.set(year, 1 (for Jan) - 1 = 0...)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Date and Time
You are viewing a single comment's thread. Return to all comments →
Because months are zero indexed so Jan is 0, Feb is 1, etc. The input for month is the number format we recognize (Jan is 1, Feb is 2, etc.). Subtracting 1 from the input will give the correct value to set the Calendar month: Input: month = 1 (for Jan) Calendar.set(year, 1 (for Jan) - 1 = 0...)