Calendar getTimeInMillis() in Java

getTimeInMillis(): This method is available in java.util.Calendar class of Java.

Syntax:

long java.util.Calendar.getTimeInMillis()

This method returns this Calendar's time value in milliseconds.

Parameters: NA

Returns: the current time as UTC milliseconds from the epoch.

Exceptions: NA

Approach

Java

import java.util.Calendar;

public class CalendargetTimeInMillis {
    public static void main(String[] args) {

        // create a calendar
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 2);

        System.out.println(calendar.getTimeInMillis());
    }
}

Output:

1643092098501


No comments:

Post a Comment