Add 1 Week to a Date, which way is preferred?

前端 未结 10 1756
迷失自我
迷失自我 2021-01-07 17:30

I am reviewing some code at work and came across an inconsistency in how the code handles adding 1 week to the current time and was wondering if there was any reason why one

10条回答
  •  旧巷少年郎
    2021-01-07 18:07

    Since you're using it on the mobile device, the first method is preferable. The reason is that your code should be independent of specific calendar, DST and other problems, such as seconds overrun(leap seconds).

    You have to remove dependence on GregorianCalendar and create it using Calendar.getInstance().

提交回复
热议问题