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.tutorialspoint;
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

