java.util.Calendar.getTime() 方法返回一個Date物件,它表示此Calendar的時間值
以下是java.util.Calendar.getTime()方法的宣告
public final Date getTime()
NA
該方法返回一個代表時間值日期。
NA
下面的範例演示java.util.calendar.getTime()方法的用法。
package com.yiibai; 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