Calendar类中的getTimeInMillis()方法用于返回此日历的当前时间(以毫秒为单位)。
用法:
public long getTimeInMillis()
参数:该方法不包含任何参数。
返回值:该方法以毫秒为单位返回此日历的当前时间。
以下示例程序旨在说明Calendar类的getTimeInMillis()方法的用法:
示例1:
// Java code to illustrate
// getTimeInMillis() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
throws InterruptedException
{
// Creating a calendar
Calendar calndr1 = Calendar.getInstance();
// Displaying the current time
System.out.println("The Current Time"
+ " is: "
+ calndr1.getTimeInMillis());
// Adding few delay
Thread.sleep(10000);
// Creating another calendar
Calendar calndr2 = Calendar.getInstance();
// Displaying the upcoming time
System.out.println("The Upcoming Time"
+ " is: "
+ calndr2.getTimeInMillis());
}
}
输出:
The Current Time is: 1550725664034 The Upcoming Time is: 1550725674053
示例2:
// Java code to illustrate
// getTimeInMillis() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
throws InterruptedException
{
// Creating a calendar
Calendar calndr1 = Calendar.getInstance();
// Displaying the current time
System.out.println("The Current Time"
+ " is: "
+ calndr1.getTimeInMillis());
// Adding few delay
Thread.sleep(5000);
// Creating another calendar
Calendar calndr2 = Calendar.getInstance();
// Displaying the upcoming time
System.out.println("The Upcoming Time"
+ " is: "
+ calndr2.getTimeInMillis());
}
}
输出:
The Current Time is: 1550725683182 The Upcoming Time is: 1550725688208
参考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getTimeInMillis–
相关用法
- Java Calendar set()用法及代码示例
- Java Calendar get()用法及代码示例
- Java Calendar add()用法及代码示例
- Java Calendar isSet()用法及代码示例
- Java Calendar internalGet()用法及代码示例
- Java Calendar getAvailableLocales()用法及代码示例
- Java Calendar getTimeZone()用法及代码示例
- Java Calendar getInstance()用法及代码示例
- Java Calendar getDisplayName()用法及代码示例
- Java Calendar getDisplayNames()用法及代码示例
- Java Calendar getGreatestMinimum()用法及代码示例
- Java Calendar getFirstDayOfWeek()用法及代码示例
- Java Calendar getLeastMaximum()用法及代码示例
- Java Calendar hashCode()用法及代码示例
- Java Calendar getTime()用法及代码示例
注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Calendar getTimeInMillis() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。