Added in API level 1

Date

public class Date
extends Date

java.lang.Object
   ↳ java.util.Date
     ↳ java.sql.Date


A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.

To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

Summary

Public constructors

Date(int year, int month, int day)

This constructor is deprecated. instead use the constructor Date(long date)

Date(long date)

Constructs a Date object using the given milliseconds time value.

Public methods

int getHours()

This method is deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component.

int getMinutes()

This method is deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component.

int getSeconds()

This method is deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component.

void setHours(int i)

This method is deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component.

void setMinutes(int i)

This method is deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component.

void setSeconds(int i)

This method is deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component.

void setTime(long date)

Sets an existing Date object using the given milliseconds time value.

String toString()

Formats a date in the date escape format yyyy-mm-dd.

static Date valueOf(String s)

Converts a string in JDBC date escape format to a Date value.

Inherited methods

static long UTC(int year, int month, int date, int hrs, int min, int sec)

This method was deprecated in API level 15. 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().

boolean after(Date when)

Tests if this date is after the specified date.

boolean before(Date when)

Tests if this date is before the specified date.

Object clone()

Return a copy of this object.

int compareTo(Date anotherDate)

Compares two Dates for ordering.

boolean equals(Object obj)

Compares two dates for equality.

static Date from(Instant instant)

Obtains an instance of Date from an Instant object.

int getDate()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_MONTH).

int getDay()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_WEEK).

int getHours()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.HOUR_OF_DAY).

int getMinutes()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.MINUTE).

int getMonth()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.MONTH).

int getSeconds()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.SECOND).

long getTime()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

int getTimezoneOffset()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by -(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000).

int getYear()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.

int hashCode()

Returns a hash code value for this object.

static long parse(String s)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by DateFormat.parse(String s).

void setDate(int date)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date).

void setHours(int hours)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.set(Calendar.HOUR_OF_DAY, int hours).

void setMinutes(int minutes)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.set(Calendar.MINUTE, int minutes).

void setMonth(int month)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.set(Calendar.MONTH, int month).

void setSeconds(int seconds)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.set(Calendar.SECOND, int seconds).

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.

void setYear(int year)

This method was deprecated in API level 15. As of JDK version 1.1, replaced by Calendar.set(Calendar.YEAR, year + 1900).

String toGMTString()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by DateFormat.format(Date date), using a GMT TimeZone.

Instant toInstant()

Converts this Date object to an Instant.

String toLocaleString()

This method was deprecated in API level 15. As of JDK version 1.1, replaced by DateFormat.format(Date date).

String toString()

Converts this Date object to a String of the form:

 dow mon dd hh:mm:ss zzz yyyy
where:
  • dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

abstract int compareTo(Date o)

Compares this object with the specified object for order.

Public constructors

Date

Added in API level 1
public Date (int year, 
                int month, 
                int day)

This constructor is deprecated.
instead use the constructor Date(long date)

Constructs a Date object initialized with the given year, month, and day.

The result is undefined if a given argument is out of bounds.

Parameters
year int: the year minus 1900; must be 0 to 8099. (Note that 8099 is 9999 minus 1900.)

month int: 0 to 11

day int: 1 to 31

Date

Added in API level 1
public Date (long date)

Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.

Parameters
date long: milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.

Public methods

getHours

Added in API level 1
public int getHours ()

This method is deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.

Returns the hour represented by this Date object. The returned value is a number (0 through 23) representing the hour within the day that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Returns
int the hour represented by this date.

Throws
IllegalArgumentException if this method is invoked

See also:

getMinutes

Added in API level 1
public int getMinutes ()

This method is deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.

Returns the number of minutes past the hour represented by this date, as interpreted in the local time zone. The value returned is between 0 and 59.

Returns
int the number of minutes past the hour represented by this date.

Throws
IllegalArgumentException if this method is invoked

See also:

getSeconds

Added in API level 1
public int getSeconds ()

This method is deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.

Returns the number of seconds past the minute represented by this date. The value returned is between 0 and 61. The values 60 and 61 can only occur on those Java Virtual Machines that take leap seconds into account.

Returns
int the number of seconds past the minute represented by this date.

Throws
IllegalArgumentException if this method is invoked

See also:

setHours

Added in API level 1
public void setHours (int i)

This method is deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.

Sets the hour of this Date object to the specified value. This Date object is modified so that it represents a point in time within the specified hour of the day, with the year, month, date, minute, and second the same as before, as interpreted in the local time zone.

Parameters
i int: the hour value.

Throws
IllegalArgumentException if this method is invoked

See also:

setMinutes

Added in API level 1
public void setMinutes (int i)

This method is deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.

Sets the minutes of this Date object to the specified value. This Date object is modified so that it represents a point in time within the specified minute of the hour, with the year, month, date, hour, and second the same as before, as interpreted in the local time zone.

Parameters
i int: the value of the minutes.

Throws
IllegalArgumentException if this method is invoked

See also:

setSeconds

Added in API level 1
public void setSeconds (int i)

This method is deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.

Sets the seconds of this Date to the specified value. This Date object is modified so that it represents a point in time within the specified second of the minute, with the year, month, date, hour, and minute the same as before, as interpreted in the local time zone.

Parameters
i int: the seconds value.

Throws
IllegalArgumentException if this method is invoked

See also:

setTime

Added in API level 1
public void setTime (long date)

Sets an existing Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.

Parameters
date long: milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.

toString

Added in API level 1
public String toString ()

Formats a date in the date escape format yyyy-mm-dd.

Returns
String a String in yyyy-mm-dd format

valueOf

Added in API level 1
public static Date valueOf (String s)

Converts a string in JDBC date escape format to a Date value.

Parameters
s String: a String object representing a date in in the format "yyyy-[m]m-[d]d". The leading zero for mm and dd may also be omitted.

Returns
Date a java.sql.Date object representing the given date

Throws
IllegalArgumentException if the date given is not in the JDBC date escape format (yyyy-[m]m-[d]d)