Java.util.Calendar类

java.util.Calendar.computeTime() 方法用于将 fields[] 中的当前日历字段值转换为毫秒时间值time。

语法

protected abstract void computeTime()

参数

无需参数。

返回值

void 类型。

异常

无。

示例:

在下面的示例中, java.util.Calendar.computeTime()方法用于将当前日历字段值转换为毫秒时间值。

import java.util.*;

public class MyClass extends GregorianCalendar {
  public static void main(String[] args) {
    //创建日历对象
    MyClass Cal = new MyClass();

    //打印当前日期
    System.out.println("The current date is: " + Cal.getTime());

    //设置为新的一年
    Cal.set(Calendar.YEAR, 2015);
    System.out.println("The new date is: " + Cal.getTime());

    //计算时间并打印日期
    Cal.computeFields();
    System.out.println("The new date is: " + Cal.getTime());
  }
}

上面的输出代码为:

The current date is: Thu Sep 10 05:41:46 UTC 2020
The new date is: Thu Sep 10 05:41:46 UTC 2015
The new date is: Thu Sep 10 05:41:46 UTC 2015