Calendar getTimeInMillis() Method in Java with Examples
Last Updated :
26 Jul, 2021
The getTimeInMillis() method in Calendar class is used to return the current time of this Calendar in Milliseconds.
Syntax:
public long getTimeInMillis()
Parameters: The method does not take any parameters.
Return Value: The method returns the current time of this Calendar in millisecond.
Below programs illustrate the working of getTimeInMillis() Method of Calendar class:
Example 1:
Java
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
throws InterruptedException
{
Calendar calndr1 = Calendar.getInstance();
System.out.println( "The Current Time"
+ " is: "
+ calndr1.getTimeInMillis());
Thread.sleep( 10000 );
Calendar calndr2 = Calendar.getInstance();
System.out.println( "The Upcoming Time"
+ " is: "
+ calndr2.getTimeInMillis());
}
}
|
Output:
The Current Time is: 1550725664034
The Upcoming Time is: 1550725674053
Example 2:
Java
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
throws InterruptedException
{
Calendar calndr1 = Calendar.getInstance();
System.out.println( "The Current Time"
+ " is: "
+ calndr1.getTimeInMillis());
Thread.sleep( 5000 );
Calendar calndr2 = Calendar.getInstance();
System.out.println( "The Upcoming Time"
+ " is: "
+ calndr2.getTimeInMillis());
}
}
|
Output:
The Current Time is: 1550725683182
The Upcoming Time is: 1550725688208
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getTimeInMillis–
Share your thoughts in the comments
Please Login to comment...