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

前端 未结 10 1370
星月不相逢
星月不相逢 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:32

    You essentially advance the date by one, in both the cases. So there is no difference in both the approaches.

    But sticking to a single method will render consistency across your codebase, maintainers will feel at home and probably the runtime optimizes the method call by compiling it as well.

提交回复
热议问题