当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Java.util.Calendar.computeTime()用法及代码示例



描述

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

声明

以下是声明java.util.Calendar.computeFields()方法

protected abstract void computeTime()

参数

NA

返回值

此方法不返回任何值。

异常

NA

示例

下面的例子展示了 java.util.Calendar.computeTime() 方法的用法。

package com.tutorialspoint;

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 computeTime()
      cal.set(GregorianCalendar.YEAR, 1998);
      cal.computeTime();

      // print the current date
      System.out.println("New date is:" + cal.getTime());
   }
}

让我们编译并运行上面的程序,这将产生以下结果——

The current date is:Thu Jun 21 15:35:42 EEST 2012
New date is:Thu Jan 01 00:00:00 EET 1998

相关用法


注:本文由纯净天空筛选整理自 Java.util.Calendar.computeTime() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。