Top Description Fields Constructors Methods
java.sql

public Class Date

extends Date
Class Inheritance
Imports
java.time.Instant, .LocalDate

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.

Since
1.1

Field Summary

Modifier and TypeField and Description
pack-priv static final long
serialVersionUID

Hides java.util.Date.serialVersionUID.

Private serial version unique ID to ensure serialization compatibility.

Constructor Summary

AccessConstructor and Description
public
Date(int
the year minus 1900; must be 0 to 8099. (Note that 8099 is 9999 minus 1900.)
year
,
int
0 to 11
month
,
int
1 to 31
day
)
Deprecated since 1.2. instead use the constructor Date(long date)

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

public
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.
date
)

Constructs a Date object using the given milliseconds time value.

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
formatDecimalInt(int
Value to convert
val
,
char[]
Array containing converted value
buf
,
int
Starting pos in buf
offset
,
int
length of output value
len
)

Formats an unsigned integer into a char array in decimal output format.

public int
getHours()

Overrides java.util.Date.getHours.

Deprecated since 1.2.

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

public int
getMinutes()

Overrides java.util.Date.getMinutes.

Deprecated since 1.2.

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

public int
getSeconds()

Overrides java.util.Date.getSeconds.

Deprecated since 1.2.

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

public void
setHours(int
the hour value.
i
)

Overrides java.util.Date.setHours.

Deprecated since 1.2.

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

public void
setMinutes(int
the value of the minutes.
i
)

Overrides java.util.Date.setMinutes.

Deprecated since 1.2.

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

public void
setSeconds(int
the seconds value.
i
)

Overrides java.util.Date.setSeconds.

Deprecated since 1.2.

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

public void
setTime(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.
date
)

Overrides java.util.Date.setTime.

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

public Instant
toInstant()

Overrides java.util.Date.toInstant.

This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.

public LocalDate

Returns:

a LocalDate object representing the same date value
toLocalDate
()

Creates a LocalDate instance using the year, month and day from this Date object.

public String

Returns:

a String in yyyy-mm-dd format
toString
()

Overrides java.util.Date.toString.

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

public static Date

Returns:

a java.sql.Date object representing the given date
valueOf
(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.
s
)

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

public static Date

Returns:

a Date object
valueOf
(LocalDate
a LocalDate to convert
date
)

Obtains an instance of Date from a LocalDate object with the same year, month and day of month value as the given LocalDate.

Inherited from java.util.Date:
afterbeforeclonecompareToequalsfromgetDategetDaygetMonthgetTimegetTimezoneOffsetgetYearhashCodeparsesetDatesetMonthsetYeartoGMTStringtoLocaleStringUTC

Field Detail

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.util.Date.serialVersionUID.

Private serial version unique ID to ensure serialization compatibility.

Constructor Detail

Dateback to summary
public Date(int year, int month, int day)

Deprecated

since 1.2.

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

Annotations
@Deprecated
since:1.2
Dateback to summary
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.

Method Detail

formatDecimalIntback to summary
pack-priv static void formatDecimalInt(int val, char[] buf, int offset, int len)

Formats an unsigned integer into a char array in decimal output format. Numbers will be zero-padded or truncated if the string representation of the integer is smaller than or exceeds len, respectively. Should consider moving this to Integer and expose it through JavaLangAccess similar to Integer::formatUnsignedInt

Parameters
val:int

Value to convert

buf:char[]

Array containing converted value

offset:int

Starting pos in buf

len:int

length of output value

getHoursback to summary
public int getHours()

Overrides java.util.Date.getHours.

Deprecated

since 1.2.

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

Returns:int

Doc from java.util.Date.getHours.

the hour represented by this date.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
setHours
getMinutesback to summary
public int getMinutes()

Overrides java.util.Date.getMinutes.

Deprecated

since 1.2.

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

Returns:int

Doc from java.util.Date.getMinutes.

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

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
setMinutes
getSecondsback to summary
public int getSeconds()

Overrides java.util.Date.getSeconds.

Deprecated

since 1.2.

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

Returns:int

Doc from java.util.Date.getSeconds.

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

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
setSeconds
setHoursback to summary
public void setHours(int i)

Overrides java.util.Date.setHours.

Deprecated

since 1.2.

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

Parameters
i:int

Doc from java.util.Date.setHours.

the hour value.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
getHours
setMinutesback to summary
public void setMinutes(int i)

Overrides java.util.Date.setMinutes.

Deprecated

since 1.2.

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

Parameters
i:int

Doc from java.util.Date.setMinutes.

the value of the minutes.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
getMinutes
setSecondsback to summary
public void setSeconds(int i)

Overrides java.util.Date.setSeconds.

Deprecated

since 1.2.

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

Parameters
i:int

Doc from java.util.Date.setSeconds.

the seconds value.

Annotations
@Deprecated
since:1.2
Exceptions
IllegalArgumentException:
if this method is invoked
See Also
getSeconds
setTimeback to summary
public void setTime(long date)

Overrides java.util.Date.setTime.

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.

toInstantback to summary
public Instant toInstant()

Overrides java.util.Date.toInstant.

This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.

Returns:Instant

Doc from java.util.Date.toInstant.

an instant representing the same point on the time-line as this Date object

Annotations
@Override
Exceptions
UnsupportedOperationException:
if this method is invoked
toLocalDateback to summary
public LocalDate toLocalDate()

Creates a LocalDate instance using the year, month and day from this Date object.

Returns:LocalDate

a LocalDate object representing the same date value

Annotations
@SuppressWarnings:deprecation
Since
1.8
toStringback to summary
public String toString()

Overrides java.util.Date.toString.

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

Returns:String

a String in yyyy-mm-dd format

Annotations
@SuppressWarnings:deprecation
valueOfback to summary
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

Exceptions
IllegalArgumentException:
if the date given is not in the JDBC date escape format (yyyy-[m]m-[d]d)
valueOfback to summary
public static Date valueOf(LocalDate date)

Obtains an instance of Date from a LocalDate object with the same year, month and day of month value as the given LocalDate.

The provided LocalDate is interpreted as the local date in the local time zone.

Parameters
date:LocalDate

a LocalDate to convert

Returns:Date

a Date object

Annotations
@SuppressWarnings:deprecation
Exceptions
NullPointerException:
if date is null
Since
1.8