protected abstract void computeFields()
描述 (Description)
java.util.Calendar.computeFields()方法将当前毫秒时间值时间转换为fields []中的日历字段值。 这允许使用为日历对象设置的新时间与日历字段值同步。
声明 (Declaration)
以下是java.util.Calendar.computeFields()方法的声明
protected abstract void computeFields()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回任何值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.GregorianCalendar.computeFields()方法的用法。
package com.iowiki;
import java.util.*;
public class CalendarDemo extends GregorianCalendar {
public static void main(String[] args) {
// create a new calendar
CalendarDemo cal = new CalendarDemo();
// print the current date
System.out.println("The current date is : " + cal.getTime());
// clear the calendar
cal.clear();
// set a new year and call computeFields()
cal.set(GregorianCalendar.YEAR, 1998);
cal.computeFields();
// print the current date
System.out.println("New date is : " + cal.getTime());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
The current date is : Thu Jun 21 15:34:36 EEST 2012
New date is : Thu Jun 21 15:34:36 EEST 2012