add more than 30 days with Calendar's add() method in Java

前端 未结 2 1806
遥遥无期
遥遥无期 2021-02-13 09:56

I\'m not quite sure what field to use when adding more than 30 days to a Java Calendar object. Is there any difference in between Calendar.DAY_OF_MONTH and Ca

2条回答
  •  花落未央
    2021-02-13 10:56

    I don't think it makes a difference when you call add. The distinction is important when you call the getters.

    Both methods work fine, right? For more than 30 days, as well as negative amounts.

    The (admittedly complicated) source for GregorianCalendar#add has this section:

     case DAY_OF_MONTH: // synonym of DATE
     case DAY_OF_YEAR:
     case DAY_OF_WEEK:
        break;
    

提交回复
热议问题