java.util.Calendar getTimeInMillis()方法
java.util.Calendar.getTimeInMillis() 方法返回此Calendar以毫秒为单位的时间。
1 语法
public long getTimeInMillis()
2 参数
无
3 返回值
该方法返回当前时间的UTC毫秒。
4 示例1
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.util.Calendar getTimeInMillis()方法的例子
*/
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
热门文章
优秀文章