Package java.sql
Class Date
java.lang.Object
java.util.Date
java.sql.Date
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<Date>
public class Date extends 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.
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description intgetHours()Deprecated.This method is deprecated and must not be used.intgetMinutes()Deprecated.This method is deprecated and must not be used.intgetSeconds()Deprecated.This method is deprecated and must not be used.voidsetHours(int theHours)Deprecated.This method is deprecated and must not be used.voidsetMinutes(int theMinutes)Deprecated.This method is deprecated and must not be used.voidsetSeconds(int theSeconds)Deprecated.This method is deprecated and must not be used.voidsetTime(long theTime)Sets this date to a date supplied as a milliseconds value.StringtoString()Produces a string representation of the date in SQL formatstatic DatevalueOf(String dateString)Creates aDatefrom a string representation of a date in SQL format.
-
Constructor Details
-
Date
Deprecated.Use the constructorDate(long)instead.Constructs aDateobject corresponding to the supplied year, month and day.- Parameters:
theYear- the year, specified as the year minus 1900. Must be in the range[0,8099].theMonth- the month, specified as a number with 0 = January. Must be in the range[0,11].theDay- the day in the month. Must be in the range[1,31].
-
Date
public Date(long theDate)Creates a date which corresponds to the day determined by the supplied milliseconds time valuetheDate.- Parameters:
theDate- a time value in milliseconds since the epoch - January 1 1970 00:00:00 GMT. The time value (hours, minutes, seconds, milliseconds) stored in theDateobject is adjusted to correspond to 00:00:00 GMT on the day determined by the supplied time value.
-
-
Method Details
-
getHours
Deprecated.This method is deprecated and must not be used. SQLDatevalues do not have an hours component.Description copied from class:DateReturns the gregorian calendar hour of the day for thisDateobject.- Overrides:
getHoursin classDate- Returns:
- does not return anything.
- Throws:
IllegalArgumentException- if this method is called.
-
getMinutes
Deprecated.This method is deprecated and must not be used. SQLDatevalues do not have a minutes component.Description copied from class:DateReturns the gregorian calendar minute of the hour for thisDateobject.- Overrides:
getMinutesin classDate- Returns:
- does not return anything.
- Throws:
IllegalArgumentException- if this method is called.
-
getSeconds
Deprecated.This method is deprecated and must not be used. SQLDatevalues do not have a seconds component.Description copied from class:DateReturns the gregorian calendar second of the minute for thisDateobject.- Overrides:
getSecondsin classDate- Returns:
- does not return anything.
- Throws:
IllegalArgumentException- if this method is called.
-
setHours
Deprecated.This method is deprecated and must not be used. SQLDatevalues do not have an hours component.Description copied from class:DateSets the gregorian calendar hour of the day for thisDateobject.- Overrides:
setHoursin classDate- Parameters:
theHours- the number of hours to set.- Throws:
IllegalArgumentException- if this method is called.
-
setMinutes
Deprecated.This method is deprecated and must not be used. SQLDatevalues do not have a minutes component.Description copied from class:DateSets the gregorian calendar minute of the hour for thisDateobject.- Overrides:
setMinutesin classDate- Parameters:
theMinutes- the number of minutes to set.- Throws:
IllegalArgumentException- if this method is called.
-
setSeconds
Deprecated.This method is deprecated and must not be used. SQLDatevalues do not have a seconds component.Description copied from class:DateSets the gregorian calendar second of the minute for thisDateobject.- Overrides:
setSecondsin classDate- Parameters:
theSeconds- the number of seconds to set.- Throws:
IllegalArgumentException- if this method is called.
-
setTime
public 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. -
toString
Produces a string representation of the date in SQL format -
valueOf
Creates aDatefrom a string representation of a date in SQL format.- Parameters:
dateString- the string representation of a date in SQL format - "yyyy-MM-dd".- Returns:
- the
Dateobject. - Throws:
IllegalArgumentException- if the format of the supplied string does not match the SQL format.
-
Date(long)instead.