Calendar getTime() in Java

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

Syntax:

Date java.util.Calendar.getTime()

This method returns a Date object representing this Calendar's time value.

Parameters: NA

Returns: a Date representing the time value.

Exceptions: NA

Approach

Java

import java.util.Calendar;

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

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

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

Output:

Tue Jan 25 11:54:15 IST 2022


No comments:

Post a Comment