Java – Date Class

Java Date Class methods, constructors, variables available in Java 8 release are listed below. We will publish example program on each methods ASAP.

Constructors in Java Date Class

S.No Constructor & 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(int year, int month, int date)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).
3 Date(int year, int month, int date, int hrs, int min)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date, hrs, min) or GregorianCalendar(year + 1900, month, date, hrs, min).
4 Date(int year, int month, int date, int hrs, int min, int sec)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date, hrs, min, sec) or GregorianCalendar(year + 1900, month, date, hrs, min, sec).
5 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.
6 Date(String s)

Deprecated.
As of JDK version 1.1, replaced by DateFormat.parse(String s).

Methods in Java Date Class

S.No Method & 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 int getDate()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_MONTH).
8 int getDay()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_WEEK).
9 int getHours()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.HOUR_OF_DAY).
10 int getMinutes()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.MINUTE).
11 int getMonth()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.MONTH).
12 int getSeconds()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.SECOND).
13 long getTime()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
14 int getTimezoneOffset()

Deprecated.
As of JDK version 1.1, replaced by -(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000).
15 int getYear()

Deprecated.
As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) – 1900.
16 int hashCode()

Returns a hash code value for this object.
17 static long parse(String s)

Deprecated.
As of JDK version 1.1, replaced by DateFormat.parse(String s).
18 void setDate(int date)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date).
19 void setHours(int hours)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(Calendar.HOUR_OF_DAY, int hours).
20 void setMinutes(int minutes)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(Calendar.MINUTE, int minutes).
21 void setMonth(int month)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(Calendar.MONTH, int month).
22 void setSeconds(int seconds)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(Calendar.SECOND, int seconds).
23 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.
24 void setYear(int year)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(Calendar.YEAR, year + 1900).
25 String toGMTString()

Deprecated.
As of JDK version 1.1, replaced by DateFormat.format(Date date), using a GMT TimeZone.
26 Instant toInstant()

Converts this Date object to an Instant.
27 String toLocaleString()

Deprecated.
As of JDK version 1.1, replaced by DateFormat.format(Date date).
28 String toString()

Converts this Date object to a String of the form:
29 static long UTC(int year, int month, int date, int hrs, int min, int sec)

Deprecated.
As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date, hrs, min, sec) or GregorianCalendar(year + 1900, month, date, hrs, min, sec), using a UTC TimeZone, followed by Calendar.getTime().getTime().

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java ArrayList ensureCapacity() method with example
  2. Java – ListIterator Interface
  3. Java – Spliterator.OfInt Interface
  4. Java – AbstractList Class
  5. Java – ConcurrentMap Interface
  6. Java – PrimitiveIterator.OfInt Interface
  7. Java – IntSummaryStatistics Class
  8. Java – ArrayBlockingQueue Class
  9. Java – ToIntBiFunction Interface
  10. Java – EventListenerProxy Class
  11. Java – IntStream.Builder Interface
  12. Java – Calendar.Builder Class
  13. Java – BooleanSupplier Interface
  14. Java ArrayList subList() method with example
  15. Java ArrayList indexOf() method with example

Be the first to comment

Leave a Reply