Java Utility Library
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Java.util.Date Class



Java Date Class

Java.util package provides a Date class which represents a specific instant in time, with millisecond precision.

Class declaration

The declaration of java.util.Date class is:

public class Date
  extends Object
    implements Serializable, Cloneable, Comparable<Date>

Class Constructors

S.NConstructors & Description
1. Date()
Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
2. Date(long date)
Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

java.util.Date Methods

The java.util.Date class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. boolean after(Date when)
Tests if this date is after the specified date.
2. boolean before(Date when)
Tests if this date is before the specified date.
3. Object clone()
Return a copy of this object.
4. int compareTo(Date anotherDate)
Compares two Dates for ordering.
5. boolean equals(Object obj)
Compares two dates for equality.
6. static Date from(Instant instant)
Obtains an instance of Date from an Instant object.
7. long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
8. int hashCode()
Returns a hash code value for this object.
9. void setTime(long time)
Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.
10. Instant toInstant()
Converts this Date object to an Instant.
11. String toString()
Returns this Date object to a String form.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object

5