java.util.Calendar computeTime()方法

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

1 语法

protected abstract void computeTime()

2 参数

3 返回值

4 示例1 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Calendar computeTime()方法的例子
 */
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

 

 

热门文章

优秀文章