结果
上面的代码示例将产生以下结果。
today is Mon Jun 22 02:44:36 IST 2009
date after a month will be Thu Oct 22 02:44:36 IST 2009
date after 7 hrs will be Thu Oct 22 00:44:36 IST 2009
以下是滚动月份的另一个示例。
import java.util.Calendar;
public class CalendarExample {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println("Time:" + cal.getTime());
cal.roll(Calendar.YEAR, false);
System.out.println("Time rolling down the year:" + cal.getTime());
cal.roll(Calendar.HOUR, true);
System.out.println("Time rolling up the hour:" + cal.getTime());
}
}
上面的代码示例将产生以下结果。
Time:Fri Nov 11 07:01:31 UTC 2016
Time rolling down the year:Wed Nov 11 07:01:31 UTC 2015
Time rolling up the hour:Wed Nov 11 08:01:31 UTC 2015