Datepublic class Date extends Date A class which can consume and produce dates in SQL {@code Date} format.
Dates are represented in SQL as {@code 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 {@code 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 {@code
java.sql.Date} class are "normalized" to the time 00:00:00.000 GMT on the
date implied by the time value.
|
Fields Summary |
---|
private static final long | serialVersionUID |
Constructors Summary |
---|
public Date(int theYear, int theMonth, int theDay)Constructs a {@code Date} object corresponding to the supplied year,
month and day.
super(theYear, theMonth, theDay);
| public Date(long theDate)Creates a date which corresponds to the day determined by the supplied
milliseconds time value {@code theDate}.
super(normalizeTime(theDate));
|
Methods Summary |
---|
public int | getHours()
throw new IllegalArgumentException();
| public int | getMinutes()
throw new IllegalArgumentException();
| public int | getSeconds()
throw new IllegalArgumentException();
| private static long | normalizeTime(long theTime)
return theTime;
| public void | setHours(int theHours)
throw new IllegalArgumentException();
| public void | setMinutes(int theMinutes)
throw new IllegalArgumentException();
| public void | setSeconds(int theSeconds)
throw new IllegalArgumentException();
| 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.
/*
* Store the Date based on the supplied time after removing any time
* elements finer than the day based on zero GMT
*/
super.setTime(normalizeTime(theTime));
| public java.lang.String | toString()Produces a string representation of the date in SQL format
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
return dateFormat.format(this);
| public static java.sql.Date | valueOf(java.lang.String dateString)Creates a {@code Date} from a string representation of a date in SQL
format.
if (dateString == null) {
throw new IllegalArgumentException();
}
int firstIndex = dateString.indexOf('-");
int secondIndex = dateString.indexOf('-", firstIndex + 1);
// secondIndex == -1 means none or only one separator '-' has been
// found.
// The string is separated into three parts by two separator characters,
// if the first or the third part is null string, we should throw
// IllegalArgumentException to follow RI
if (secondIndex == -1 || firstIndex == 0
|| secondIndex + 1 == dateString.length()) {
throw new IllegalArgumentException();
}
// parse each part of the string
int year = Integer.parseInt(dateString.substring(0, firstIndex));
int month = Integer.parseInt(dateString.substring(firstIndex + 1,
secondIndex));
int day = Integer.parseInt(dateString.substring(secondIndex + 1,
dateString.length()));
return new Date(year - 1900, month - 1, day);
|
|