ITeye博客

Calendar roll & add

superfofo · 2012-04-19 15:06 · others · 编程语言 · Markdown

Calendar.roll() Changes a specific unit and leaves 'larger' (in terms of time-month is 'larger' than day) units unchanged. The API example is that given a date of August 31, 1999, rolling by (Calendar.MONTH, 8) yields April 30, 1999. That is, the DAY was changed to meet April's maximum, but the 'larger' unit, YEAR, was unchanged.

    Calendar.add()
    Will cause the next 'larger' unit to change, if necessary. That is, given a date of August 31, 1999, add(Calendar.MONTH, 8) yields April 30, 2000. add() also forces a recalculation of milliseconds and all fields.

http://stackoverflow.com/questions/2504141/calendar-add-vs-roll-when-do-we-use-it

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。