Java-util-calendar-complete

提供:Dev Guides
移動先:案内検索

Java.util.Calendar.complete()メソッド

説明

  • java.util.Calendar.complete()*メソッドは、カレンダーフィールドの未設定フィールドを埋めます。 最初に、時間値(エポックからのミリ秒オフセット)がカレンダーフィールド値から計算されていない場合、computeTime()メソッドが呼び出されます。 次に、computeFields()メソッドが呼び出され、すべてのカレンダーフィールド値が計算されます。

宣言

以下は* java.util.Calendar.complete()*メソッドの宣言です

protected void complete()

パラメーター

NA

戻り値

このメソッドは値を返しません。

例外

NA

次の例は、java.util.Calendar.complete()メソッドの使用法を示しています。

package com.finddevguides;

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

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

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

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