Java Date and Time

  • + 0 comments

    In this code there is one cofusion every begginer will face that is why month -1 is there in this line of code:

    calendar.set(year, month-1, day);

    Explanation : Calendar class represents months as 0-indexed.

    So January is 0, February is 1, ... November is 10 and December is 11. So if we are giving Aughust which 8th month. you must pass 7 (i.e., 8 - 1).

    as