Saturday, February 7, 2026
HomeLanguagesJavaCalendar getTimeInMillis() Method in Java with Examples

Calendar getTimeInMillis() Method in Java with Examples

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




// 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());
    }
}


Output: 

The Current Time is: 1550725664034
The Upcoming Time is: 1550725674053

 

Example 2: 
 

Java




// 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());
    }
}


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–
 

RELATED ARTICLES

Most Popular

Dominic
32492 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6863 POSTS0 COMMENTS
Nicole Veronica
11987 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12078 POSTS0 COMMENTS
Shaida Kate Naidoo
6996 POSTS0 COMMENTS
Ted Musemwa
7239 POSTS0 COMMENTS
Thapelo Manthata
6947 POSTS0 COMMENTS
Umr Jansen
6934 POSTS0 COMMENTS