java.util.Date

The java.util.Date class represents a specific instant in time, with millisecond precision. It was part of the original Java 1.0 and is located in the java.util package. Although many of its methods are deprecated in favor of the newer java.time API (Java 8+), it’s still widely used, especially when interacting with legacy systems or older APIs.

Key Characteristics

  • Represents date and time in milliseconds since January 1, 1970, 00:00:00 GMT (Unix Epoch).
  • Includes methods to get and set time.
  • Often used with SimpleDateFormat or Calendar for formatting and manipulation.
  • Several methods (e.g., getYear(), getMonth()) are deprecated due to lack of time zone and localization support.

Commonly Used Methods

Simple Program

import java.util.Date;

public class SimpleDateExample {
    public static void main(String[] args) {
        Date currentDate = new Date();
        System.out.println("Current Date and Time: " + currentDate);

        long milliseconds = currentDate.getTime();
        System.out.println("Milliseconds since January 1, 1970: " + milliseconds);
    }
}

Output

Current Date and Time: Sun May 26 15:30:10 IST 2025
Milliseconds since January 1, 1970: 1748256010000Code language: CSS (css)

The java.util.Date class plays a foundational role in Java for representing and manipulating date and time. Although many of its methods have been deprecated in favor of the more robust java.time package introduced in Java 8, it remains relevant for legacy applications and integrations with older APIs.

Scroll to Top