.getTime()

ChiragAgg5k10 total contributions
Published Sep 6, 2023
Contribute to Docs
The .getTime()
method of the Calendar
class returns a Date
object that represents the time value of a given Calendar
object.
Syntax
calendar.getTime()
Example
In the example below, a Calendar
object is created and the current date is retrieved using the .getTime()
method.
import java.util.Calendar;import java.util.Date;public class Main {public static void main(String[] args) {// Create a Calendar instanceCalendar calendar = Calendar.getInstance();// Get the current date objectDate currentDate = calendar.getTime();// Print the current dateSystem.out.println("Current date: " + currentDate);}}
The output should be similar to:
Current date: Sat Sep 02 13:10:27 GMT 2023
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.