java.util.Calendar.getTimeInMillis() 方法返回此Calendar以毫秒為單位的時間。
以下是java.util.Calendar.getTimeInMillis()方法的宣告
public long getTimeInMillis()
NA
該方法返回當前時間的UTC毫秒。
NA
下面的範例演示java.util.calendar.getTimeInMillis()方法的用法。
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 in milliseconds System.out.println("Current time is : " + cal.getTimeInMillis()); // add a delay of 2 seconds Thread.sleep(2000); // create a new calendar Calendar cal2 = Calendar.getInstance(); // print the next time in milliseconds long d = cal2.getTimeInMillis(); System.out.println("Next time is : " + d); } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
Current time is : 1336226501635 Next time is : 1336226503635