梁某人

发展才是硬道理

导航

java.util.Calendar的roll方法

不看jdk文档的教训。

原以为roll可以直接处理日期变更。原来不是,查查jdk文档,如下:

roll

public void roll(int field,
                 int amount)
Time Field Rolling function. Add to field a signed amount without changing larger fields. A negative roll amount means to roll down. [NOTE: This default implementation on Calendar just repeatedly calls the version of roll() that takes a boolean and rolls by one unit. This may not always do the right thing. For example, if the DAY_OF_MONTH field is 31, rolling through February will leave it set to 28. The GregorianCalendar version of this function takes care of this problem. Other subclasses should also provide overrides of this function that do the right thing.

Parameters:
field - the time field.
amount - the signed amount to add to field.
Since:
1.2
See Also:
add(int, int), set(int, int)



SHIT,应该用add

posted on 2004-12-16 16:01  涛仔28  阅读(1509)  评论(1编辑  收藏  举报