What's the difference between adding DAY_OF_MONTH or DAY_OF_YEAR to a Calendar object?

前端 未结 10 1347
星月不相逢
星月不相逢 2020-12-08 01:42

I want to increase a certain date by 1 day. I create a Calendar object like:

Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2012);
cal.set(Cal         


        
10条回答
  •  暖寄归人
    2020-12-08 02:41

    It doesn't make any difference when you call add. However the getters return different results :D

    code snippet from GregorianCalendar#add

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

提交回复
热议问题