Java-util-calendar-gettime

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

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

説明

  • java.util.Calendar.getTime()*メソッドは、このカレンダーの時間値を表すDateオブジェクトを返します

宣言

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

public final Date getTime()

パラメーター

NA

戻り値

このメソッドは、時間値を表す日付を返します。

例外

NA

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

package com.finddevguides;

import java.util.*;

public class CalendarDemo {

   public static void main(String[] args) throws InterruptedException {

     //create a calendar
      Calendar cal = Calendar.getInstance();

     //print current time
      System.out.println(" Current time is : " + cal.getTime());

     //add a delay of 2 seconds
      Thread.sleep(2000);

     //create a new calendar
      Calendar cal2 = Calendar.getInstance();

     //print the next time
      Date d = cal2.getTime();
      System.out.println(" Next time is : " + d);
   }
}

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

Current time is : Wed May 02 14:14:06 EEST 2012
Next time is : Wed May 02 14:14:08 EEST 2012