How to use Date Class In Java

Using Date Class in this method we will explore the date and time module provided by java.util.

Java




// Java Program to Display Current Date and Time
// Using Date class
  
// Importing required classes
import java.util.*;
  
// Class
public class GFG {
  
    // Main driver method
    public static void main(String[] args)
    {
        // Creating object of date class
        Date d1 = new Date();
  
        // Printing the value stored in above object
        System.out.println("Current date is " + d1);
    }
}


Output

Current date is Thu Nov 30 07:45:38 UTC 2023



Java – Current Date and Time

In software development, we often work with dates and times. To accurately capture the current date and time is fundamental for various applications, such as scheduling tasks, tracking events, etc.

In Java, there is a built-in class known as the Date class and we can import java.time package to work with date and time API. Here we are supposed to print the current date and time. There can be multiple ways to print the current date and time.

Different Ways To Get Current Date And Time

  1. Using Date Class
  2. Using get() method of the Calendar class
  3. Using calendar and formatter class to print the current dates in a specific format. 
  4. Using java.time.LocalDate
  5. Using java.time.LocalTime
  6. Using java.time.LocalDateTime
  7. Using java.time.Clock
  8. Using java.sql.Date

Similar Reads

Using Date Class

Using Date Class in this method we will explore the date and time module provided by java.util....

Using Calendar Instance

...

Using SimpleDateFormat

getInstance() method is generally used to get the time, date or any required some belonging to Calendar year....

Using LocalDate, LocalTime, LocalDateTime

...

Using System Clock

Using calendar and formatter class to print the current dates in a specific format....