Date getTime()
描述 (Description)
java.util.Calendar.getTime()方法返回表示此Calendar的时间值的Date对象
声明 (Declaration)
以下是java.util.Calendar.getTime()方法的声明
public final Date getTime()
参数 (Parameters)
NA
返回值 (Return Value)
该方法返回表示时间值的Date。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.calendar.getTime()方法的用法。
package com.iowiki;
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