Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Date

public class Date
extends Date

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


A class which can consume and produce dates in SQL Date format.

Dates are represented in SQL as yyyy-MM-dd. Note that this date format only deals with year, month and day values. There are no values for hours, minutes, seconds.

This is unlike the familiar java.util.Date object, which also includes values for hours, minutes, seconds, and milliseconds.

Time points are handled as millisecond values - milliseconds since the Epoch, January 1st 1970, 00:00:00.000 GMT. Time values passed to the java.sql.Date class are "normalized" to the time 00:00:00.000 GMT on the date implied by the time value.

Summary

Public constructors

Date(int theYear, int theMonth, int theDay)

This constructor was deprecated in API level 1. Use the constructor Date(long) instead.

Date(long theDate)

Creates a date which corresponds to the day determined by the supplied milliseconds time value theDate.

Public methods

int getHours()

This method is deprecated. This method is deprecated and must not be used. SQL Date values do not have an hours component.

int getMinutes()

This method is deprecated. This method is deprecated and must not be used. SQL Date values do not have a minutes component.

int getSeconds()

This method is deprecated. This method is deprecated and must not be used. SQL Date values do not have a seconds component.

void setHours(int theHours)

This method is deprecated. This method is deprecated and must not be used. SQL Date values do not have an hours component.

void setMinutes(int theMinutes)

This method is deprecated. This method is deprecated and must not be used. SQL Date values do not have a minutes component.

void setSeconds(int theSeconds)

This method is deprecated. This method is deprecated and must not be used. SQL Date values do not have a seconds component.

void setTime(long theTime)

Sets this date to a date supplied as a milliseconds value.

String toString()

Produces a string representation of the date in SQL format

static Date valueOf(String dateString)

Creates a Date from a string representation of a date in SQL format.

Inherited methods

From class java.util.Date
From class java.lang.Object
From interface java.lang.Comparable

Public constructors

Date

Added in API level 1
Date (int theYear, 
                int theMonth, 
                int theDay)

This constructor was deprecated in API level 1.
Use the constructor Date(long) instead.

Constructs a Date object corresponding to the supplied year, month and day.

Parameters
theYear int: the year, specified as the year minus 1900. Must be in the range [0,8099].
theMonth int: the month, specified as a number with 0 = January. Must be in the range [0,11].
theDay int: the day in the month. Must be in the range [1,31].

Date

Added in API level 1
Date (long theDate)

Creates a date which corresponds to the day determined by the supplied milliseconds time value theDate.

Parameters
theDate long: a time value in milliseconds since the epoch - January 1 1970 00:00:00 GMT. The time value (hours, minutes, seconds, milliseconds) stored in the Date object is adjusted to correspond to 00:00:00 GMT on the day determined by the supplied time value.

Public methods

getHours

Added in API level 1
int getHours ()

This method is deprecated.
This method is deprecated and must not be used. SQL Date values do not have an hours component.

Returns the gregorian calendar hour of the day for this Date object.

Returns
int does not return anything.
Throws
IllegalArgumentException if this method is called.

getMinutes

Added in API level 1
int getMinutes ()

This method is deprecated.
This method is deprecated and must not be used. SQL Date values do not have a minutes component.

Returns the gregorian calendar minute of the hour for this Date object.

Returns
int does not return anything.
Throws
IllegalArgumentException if this method is called.

getSeconds

Added in API level 1
int getSeconds ()

This method is deprecated.
This method is deprecated and must not be used. SQL Date values do not have a seconds component.

Returns the gregorian calendar second of the minute for this Date object.

Returns
int does not return anything.
Throws
IllegalArgumentException if this method is called.

setHours

Added in API level 1
void setHours (int theHours)

This method is deprecated.
This method is deprecated and must not be used. SQL Date values do not have an hours component.

Sets the gregorian calendar hour of the day for this Date object.

Parameters
theHours int: the number of hours to set.
Throws
IllegalArgumentException if this method is called.

setMinutes

Added in API level 1
void setMinutes (int theMinutes)

This method is deprecated.
This method is deprecated and must not be used. SQL Date values do not have a minutes component.

Sets the gregorian calendar minute of the hour for this Date object.

Parameters
theMinutes int: the number of minutes to set.
Throws
IllegalArgumentException if this method is called.

setSeconds

Added in API level 1
void setSeconds (int theSeconds)

This method is deprecated.
This method is deprecated and must not be used. SQL Date values do not have a seconds component.

Sets the gregorian calendar second of the minute for this Date object.

Parameters
theSeconds int: the number of seconds to set.
Throws
IllegalArgumentException if this method is called.

setTime

Added in API level 1
void setTime (long theTime)

Sets this date to a date supplied as a milliseconds value. The date is set based on the supplied time value and rounded to zero GMT for that day.

Parameters
theTime long: the time in milliseconds since the Epoch.

toString

Added in API level 1
String toString ()

Produces a string representation of the date in SQL format

Returns
String a string representation of the date in SQL format - "yyyy-MM-dd".

valueOf

Added in API level 1
Date valueOf (String dateString)

Creates a Date from a string representation of a date in SQL format.

Parameters
dateString String: the string representation of a date in SQL format - " yyyy-MM-dd".
Returns
Date the Date object.
Throws
IllegalArgumentException if the format of the supplied string does not match the SQL format.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.