Date
represents a specific instant
in time, with millisecond precision.
Prior to JDK 1.1, the class Date
had two additional
functions. It allowed the interpretation of dates as year, month, day, hour,
minute, and second values. It also allowed the formatting and parsing
of date strings. Unfortunately, the API for these functions was not
amenable to internationalization. As of JDK 1.1, the
Calendar
class should be used to convert between dates and time
fields and the DateFormat
class should be used to format and
parse date strings.
The corresponding methods in Date
are deprecated.
Although the Date
class is intended to reflect
coordinated universal time (UTC), it may not do so exactly,
depending on the host environment of the Java Virtual Machine.
Nearly all modern operating systems assume that 1 day =
24 × 60 × 60 = 86400 seconds
in all cases. In UTC, however, about once every year or two there
is an extra second, called a "leap second." The leap
second is always added as the last second of the day, and always
on December 31 or June 30. For example, the last minute of the
year 1995 was 61 seconds long, thanks to an added leap second.
Most computer clocks are not accurate enough to be able to reflect
the leap-second distinction.
Some computer standards are defined in terms of Greenwich mean time (GMT), which is equivalent to universal time (UT). GMT is the "civil" name for the standard; UT is the "scientific" name for the same standard. The distinction between UTC and UT is that UTC is based on an atomic clock and UT is based on astronomical observations, which for all practical purposes is an invisibly fine hair to split. Because the earth's rotation is not uniform (it slows down and speeds up in complicated ways), UT does not always flow uniformly. Leap seconds are introduced as needed into UTC so as to keep UTC within 0.9 seconds of UT1, which is a version of UT with certain corrections applied. There are other time and date systems as well; for example, the time scale used by the satellite-based global positioning system (GPS) is synchronized to UTC but is not adjusted for leap seconds. An interesting source of further information is the United States Naval Observatory (USNO):
https://www.usno.navy.mil/USNO
and the material regarding "Systems of Time" at:
https://www.usno.navy.mil/USNO/time/master-clock/systems-of-time
which has descriptions of various different time systems including UT, UT1, and UTC.
In all methods of class Date
that accept or return
year, month, date, hours, minutes, and seconds values, the
following representations are used:
- 1900
.
In all cases, arguments given to methods for these purposes need not fall within the indicated ranges; for example, a date may be specified as January 32 and is interpreted as meaning February 1.
java.text.DateFormat
, java.util.Calendar
, java.util.TimeZone
Modifier and Type | Field and Description |
---|---|
private transient BaseCalendar. | |
private static int | |
private transient long | |
private static final BaseCalendar | |
private static BaseCalendar | |
private static final long | |
private static final int[] | |
private static final String[] |
Access | Constructor and Description |
---|---|
public | Date()
Allocates a |
public | Date(long
the milliseconds since January 1, 1970, 00:00:00 GMT. date)Allocates a |
public | Date(int
the year minus 1900. year, int the month between 0-11. month, int the day of the month between 1-31. date)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(year + 1900, month, date)
or GregorianCalendar(year + 1900, month, date) .
Allocates a |
public | Date(int
the year minus 1900. year, int the month between 0-11. month, int the day of the month between 1-31. date, int the hours between 0-23. hrs, int the minutes between 0-59. min)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(year + 1900, month, date, hrs, min)
or GregorianCalendar(year + 1900, month, date, hrs, min) .
Allocates a |
public | Date(int
the year minus 1900. year, int the month between 0-11. month, int the day of the month between 1-31. date, int the hours between 0-23. hrs, int the minutes between 0-59. min, int the seconds between 0-59. sec)
Deprecated
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) .
Allocates a |
public | Date(String
a string representation of the date. s)
Deprecated
As of JDK version 1.1,
replaced by
DateFormat.parse(String s) .
Allocates a |
Modifier and Type | Method and Description |
---|---|
public boolean | |
public boolean | |
public Object | |
public int | Returns: the value0 if the argument Date is equal to
this Date; a value less than 0 if this Date
is before the Date argument; and a value greater than
0 if this Date is after the Date argument.the anotherDate)Date to be compared.Implements java. Compares two Dates for ordering. |
private static final StringBuilder | convertToAbbr(StringBuilder sb, String name)
Converts the given name to its 3-letter abbreviation (e.g.,
"monday" -> "Mon") and stored the abbreviation in the given
|
public boolean | Returns: true if the objects are the same;
false otherwise.the object to compare with. obj)Overrides java. Compares two dates for equality. |
public static Date | |
private final BaseCalendar. | |
private static final BaseCalendar | Returns: the CalendarSystem to use for the specified datenormalized calendar year (not -1900) year)Returns the Gregorian or Julian calendar system to use with the given date. |
private static final BaseCalendar | |
private static final BaseCalendar | |
public int | Returns: the day of the month represented by this date.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.DAY_OF_MONTH) .
Returns the day of the month represented by this |
public int | Returns: the day of the week represented by this date.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.DAY_OF_WEEK) .
Returns the day of the week represented by this date. |
public int | Returns: the hour represented by this date.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.HOUR_OF_DAY) .
Returns the hour represented by this |
private static final synchronized BaseCalendar | |
pack-priv static final long | getMillisOf(Date date)
Returns the millisecond value of this |
public int | Returns: the number of minutes past the hour represented by this date.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.MINUTE) .
Returns the number of minutes past the hour represented by this date, as interpreted in the local time zone. |
public int | Returns: the month represented by this date.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.MONTH) .
Returns a number representing the month that contains or begins
with the instant in time represented by this |
public int | Returns: the number of seconds past the minute represented by this date.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.SECOND) .
Returns the number of seconds past the minute represented by this date. |
public long | Returns: the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this |
private final long | |
public int | Returns: the time-zone offset, in minutes, for the current time zone.
Deprecated
As of JDK version 1.1,
replaced by
-(Calendar.get(Calendar.ZONE_OFFSET) +
Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000) .
Returns the offset, measured in minutes, for the local time zone
relative to UTC that is appropriate for the time represented by
this |
public int | Returns: the year represented by this date, minus 1900.
Deprecated
As of JDK version 1.1,
replaced by
Calendar.get(Calendar.YEAR) - 1900 .
Returns a value that is the result of subtracting 1900 from the
year that contains or begins with the instant in time represented
by this |
public int | Returns: a hash code value for this object.Overrides java. Returns a hash code value for this object. |
private final BaseCalendar. | |
private final BaseCalendar. | |
public static long | Returns: the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the string argument.a string to be parsed as a date. s)
Deprecated
As of JDK version 1.1,
replaced by
DateFormat.parse(String s) .
Attempts to interpret the string |
private void | |
public void | setDate(int
the day of the month value between 1-31. date)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(Calendar.DAY_OF_MONTH, int date) .
Sets the day of the month of this |
public void | setHours(int
the hour value. hours)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(Calendar.HOUR_OF_DAY, int hours) .
Sets the hour of this |
public void | setMinutes(int
the value of the minutes. minutes)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(Calendar.MINUTE, int minutes) .
Sets the minutes of this |
public void | setMonth(int
the month value between 0-11. month)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(Calendar.MONTH, int month) .
Sets the month of this date to the specified value. |
public void | setSeconds(int
the seconds value. seconds)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(Calendar.SECOND, int seconds) .
Sets the seconds of this |
public void | setTime(long
the number of milliseconds. time)Sets this |
public void | setYear(int
the year value. year)
Deprecated
As of JDK version 1.1,
replaced by
Calendar.set(Calendar.YEAR, year + 1900) .
Sets the year of this |
public String | Returns: a string representation of this date, using the Internet GMT conventions.
Deprecated
As of JDK version 1.1,
replaced by
DateFormat.format(Date date) , using a
GMT TimeZone .
Creates a string representation of this d mon yyyy hh:mm:ss GMT |
public Instant | Returns: an instant representing the same point on the time-line as thisDate objectConverts this |
public String | Returns: a string representation of this date, using the locale conventions.
Deprecated
As of JDK version 1.1,
replaced by
DateFormat.format(Date date) .
Creates a string representation of this |
public String | Returns: a string representation of this date.Overrides java. Converts this dow mon dd hh:mm:ss zzz yyyy |
public static long | Returns: the number of milliseconds since January 1, 1970, 00:00:00 GMT for the date and time specified by the arguments.the year minus 1900. year, int the month between 0-11. month, int the day of the month between 1-31. date, int the hours between 0-23. hrs, int the minutes between 0-59. min, int the seconds between 0-59. sec)
Deprecated
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() .
Determines the date and time based on the arguments. |
private void |
cdate | back to summary |
---|---|
private transient BaseCalendar. |
defaultCenturyStart | back to summary |
---|---|
private static int defaultCenturyStart |
fastTime | back to summary |
---|---|
private transient long fastTime |
gcal | back to summary |
---|---|
private static final BaseCalendar gcal |
jcal | back to summary |
---|---|
private static BaseCalendar jcal |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID
|
ttb | back to summary |
---|---|
private static final int[] ttb |
wtb | back to summary |
---|---|
private static final String[] wtb |
Date | back to summary |
---|---|
public Date() Allocates a
|
Date | back to summary |
---|---|
public Date(long date) Allocates a
|
Date | back to summary |
---|---|
public Date(int year, int month, int date)
Deprecated As of JDK version 1.1,
replaced by Allocates a
|
Date | back to summary |
---|---|
public Date(int year, int month, int date, int hrs, int min)
Deprecated As of JDK version 1.1,
replaced by Allocates a
|
Date | back to summary |
---|---|
public Date(int year, int month, int date, int hrs, int min, int sec)
Deprecated As of JDK version 1.1,
replaced by Allocates a
|
Date | back to summary |
---|---|
public Date(String s)
Deprecated As of JDK version 1.1,
replaced by Allocates a
|
after | back to summary |
---|---|
public boolean after(Date when) Tests if this date is after the specified date.
|
before | back to summary |
---|---|
public boolean before(Date when) Tests if this date is before the specified date.
|
clone | back to summary |
---|---|
public Object clone() Overrides java. Return a copy of this object.
|
compareTo | back to summary |
---|---|
public int compareTo(Date anotherDate) Implements java. Compares two Dates for ordering.
|
convertToAbbr | back to summary |
---|---|
private static final StringBuilder convertToAbbr(StringBuilder sb, String name) Converts the given name to its 3-letter abbreviation (e.g.,
"monday" -> "Mon") and stored the abbreviation in the given
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Compares two dates for equality.
The result is
Thus, two
|
from | back to summary |
---|---|
public static Date from(Instant instant) Obtains an instance of
|
getCalendarDate | back to summary |
---|---|
private final BaseCalendar. |
getCalendarSystem | back to summary |
---|---|
private static final BaseCalendar getCalendarSystem(int year) Returns the Gregorian or Julian calendar system to use with the given date. Use Gregorian from October 15, 1582.
|
getCalendarSystem | back to summary |
---|---|
private static final BaseCalendar getCalendarSystem(long utc) |
getCalendarSystem | back to summary |
---|---|
private static final BaseCalendar getCalendarSystem(BaseCalendar. |
getDate | back to summary |
---|---|
public int getDate()
Deprecated As of JDK version 1.1,
replaced by Returns the day of the month represented by this
|
getDay | back to summary |
---|---|
public int getDay()
Deprecated As of JDK version 1.1,
replaced by Returns the day of the week represented by this date. The
returned value (
|
getHours | back to summary |
---|---|
public int getHours()
Deprecated As of JDK version 1.1,
replaced by Returns the hour represented by this
|
getJulianCalendar | back to summary |
---|---|
private static final synchronized BaseCalendar getJulianCalendar() |
getMillisOf | back to summary |
---|---|
pack-priv static final long getMillisOf(Date date) Returns the millisecond value of this |
getMinutes | back to summary |
---|---|
public int getMinutes()
Deprecated As of JDK version 1.1,
replaced by Returns the number of minutes past the hour represented by this date,
as interpreted in the local time zone.
The value returned is between
|
getMonth | back to summary |
---|---|
public int getMonth()
Deprecated As of JDK version 1.1,
replaced by Returns a number representing the month that contains or begins
with the instant in time represented by this
|
getSeconds | back to summary |
---|---|
public int getSeconds()
Deprecated As of JDK version 1.1,
replaced by Returns the number of seconds past the minute represented by this date.
The value returned is between
|
getTime | back to summary |
---|---|
public long getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this
|
getTimeImpl | back to summary |
---|---|
private final long getTimeImpl() |
getTimezoneOffset | back to summary |
---|---|
public int getTimezoneOffset()
Deprecated As of JDK version 1.1,
replaced by Returns the offset, measured in minutes, for the local time zone
relative to UTC that is appropriate for the time represented by
this For example, in Massachusetts, five time zones west of Greenwich: because on February 14, 1996, standard time (Eastern Standard Time) is in use, which is offset five hours from UTC; but:new Date(96, 1, 14).getTimezoneOffset() returns 300 because on June 1, 1996, daylight saving time (Eastern Daylight Time) is in use, which is offset only four hours from UTC.new Date(96, 5, 1).getTimezoneOffset() returns 240 This method produces the same result as if it computed: (this.getTime() - UTC(this.getYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())) / (60 * 1000)
|
getYear | back to summary |
---|---|
public int getYear()
Deprecated As of JDK version 1.1,
replaced by Returns a value that is the result of subtracting 1900 from the
year that contains or begins with the instant in time represented
by this
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns a hash code value for this object. The result is the
exclusive OR of the two halves of the primitive
|
normalize | back to summary |
---|---|
private final BaseCalendar. |
normalize | back to summary |
---|---|
private final BaseCalendar. |
parse | back to summary |
---|---|
public static long parse(String s)
Deprecated As of JDK version 1.1,
replaced by Attempts to interpret the string It accepts many syntaxes; in particular, it recognizes the IETF standard date syntax: "Sat, 12 Aug 1995 13:30:00 GMT". It also understands the continental U.S. time-zone abbreviations, but for general use, a time-zone offset should be used: "Sat, 12 Aug 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If no time zone is specified, the local time zone is assumed. GMT and UTC are considered equivalent.
The string and whitespace characters.abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789,+-:/ A consecutive sequence of decimal digits is treated as a decimal number:
A consecutive sequence of letters is regarded as a word and treated as follows:
Once the entire string s has been scanned, it is converted to a time result in one of two ways. If a time zone or time-zone offset has been recognized, then the year, month, day of month, hour, minute, and second are interpreted in UTC and then the time-zone offset is applied. Otherwise, the year, month, day of month, hour, minute, and second are interpreted in the local time zone.
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException Reconstitute this object from a stream (i.e., deserialize it).
|
setDate | back to summary |
---|---|
public void setDate(int date)
Deprecated As of JDK version 1.1,
replaced by Sets the day of the month of this
|
setHours | back to summary |
---|---|
public void setHours(int hours)
Deprecated As of JDK version 1.1,
replaced by Sets the hour of this
|
setMinutes | back to summary |
---|---|
public void setMinutes(int minutes)
Deprecated As of JDK version 1.1,
replaced by Sets the minutes of this
|
setMonth | back to summary |
---|---|
public void setMonth(int month)
Deprecated As of JDK version 1.1,
replaced by Sets the month of this date to the specified value. This
|
setSeconds | back to summary |
---|---|
public void setSeconds(int seconds)
Deprecated As of JDK version 1.1,
replaced by Sets the seconds of this
|
setTime | back to summary |
---|---|
public void setTime(long time) Sets this
|
setYear | back to summary |
---|---|
public void setYear(int year)
Deprecated As of JDK version 1.1,
replaced by Sets the year of this
|
toGMTString | back to summary |
---|---|
public String toGMTString()
Deprecated As of JDK version 1.1,
replaced by Creates a string representation of this where:d mon yyyy hh:mm:ss GMT
The result does not depend on the local time zone.
|
toInstant | back to summary |
---|---|
public Instant toInstant() Converts this
The conversion creates an
|
toLocaleString | back to summary |
---|---|
public String toLocaleString()
Deprecated As of JDK version 1.1,
replaced by Creates a string representation of this
|
toString | back to summary |
---|---|
public String toString() Overrides java. Converts this where:dow mon dd hh:mm:ss zzz yyyy
|
UTC | back to summary |
---|---|
public static long UTC(int year, int month, int date, int hrs, int min, int sec)
Deprecated As of JDK version 1.1,
replaced by Determines the date and time based on the arguments. The
arguments are interpreted as a year, month, day of the month,
hour of the day, minute within the hour, and second within the
minute, exactly as for the
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException Save the state of this object to a stream (i.e., serialize it).
|