dede网站mip,成都 网站原创,个人工作室注册流程及费用,杭州兼职网站建设Calendar类中的roll(int calndr_field#xff0c;boolean up_down)方法用于通过上下移动传递的字段单个时间单位来对传递的日历字段进行操作。这涉及在不更改较大字段的情况下对时间字段进行加法或减法。用法:public abstract void roll(int calndr_field, boolean up_down)参…Calendar类中的roll(int calndr_fieldboolean up_down)方法用于通过上下移动传递的字段单个时间单位来对传递的日历字段进行操作。这涉及在不更改较大字段的情况下对时间字段进行加法或减法。用法:public abstract void roll(int calndr_field, boolean up_down)参数该方法有两个参数calndr_field这是日历类型是指要对其进行操作的日历字段。up_down这是布尔类型用于指示是向上或向下移动calndr_field还是增大或减小。 true表示添加时间单位false表示减去时间单位。返回值该方法不返回任何值。以下示例程序旨在说明Calendar类的roll()方法的用法示例1:// Java code to illustrate// isSet() methodimport java.util.*;public class Calendar_Demo {public static void main(String args[]){// Creating a calendarCalendar calndr Calendar.getInstance();// Displaying the yearSystem.out.println(The Current Year is: calndr.get(Calendar.YEAR));// Decrementing the year// false indicates subtractioncalndr.roll(Calendar.YEAR, false);// Displaying the result after operationSystem.out.println(The New Year is: calndr.get(Calendar.YEAR));// Incrementing the year// true indicates additioncalndr.roll(Calendar.YEAR, true);// Displaying the result after operationSystem.out.println(The new year is: calndr.get(Calendar.YEAR));}}输出The Current Year is: 2019The New Year is: 2018The new year is: 2019示例2:// Java code to illustrate// isSet() methodimport java.util.*;public class Calendar_Demo {public static void main(String args[]){// Creating a calendarCalendar calndr Calendar.getInstance();// Displaying the monthSystem.out.println(The Current Month is: calndr.get(Calendar.MONTH));// Incrementing the month// true indicates additioncalndr.roll(Calendar.MONTH, true);// Displaying the result after operationSystem.out.println(The New Month is: calndr.get(Calendar.MONTH));// Decrementing the month// false indicates subtractioncalndr.roll(Calendar.MONTH, false);// Displaying the result after operationSystem.out.println(The new month is: calndr.get(Calendar.MONTH));}}输出The Current Month is: 1The New Month is: 2The new month is: 1