public class Date extends Object implements Serializable, Cloneable, Comparable<Date>
Date
represents a specific moment in time, to the millisecond.Constructor and Description |
---|
Date()
Initializes this
Date instance to the current time. |
Date(int year,
int month,
int day)
Deprecated.
|
Date(int year,
int month,
int day,
int hour,
int minute)
Deprecated.
|
Date(int year,
int month,
int day,
int hour,
int minute,
int second)
|
Date(long milliseconds)
Initializes this
Date instance using the specified millisecond value. |
Date(String string)
Deprecated.
use
DateFormat |
Modifier and Type | Method and Description |
---|---|
boolean |
after(Date date)
Returns if this
Date is after the specified Date. |
boolean |
before(Date date)
Returns if this
Date is before the specified Date. |
Object |
clone()
Returns a new
Date with the same millisecond value as this Date . |
int |
compareTo(Date date)
Compare the receiver to the specified
Date to determine the relative
ordering. |
boolean |
equals(Object object)
Compares the specified object to this
Date and returns if they are equal. |
int |
getDate()
Deprecated.
use
Calendar.get(Calendar.DATE) |
int |
getDay()
Deprecated.
use
Calendar.get(Calendar.DAY_OF_WEEK) |
int |
getHours()
Deprecated.
use
Calendar.get(Calendar.HOUR_OF_DAY) |
int |
getMinutes()
Deprecated.
use
Calendar.get(Calendar.MINUTE) |
int |
getMonth()
Deprecated.
use
Calendar.get(Calendar.MONTH) |
int |
getSeconds()
Deprecated.
use
Calendar.get(Calendar.SECOND) |
long |
getTime()
Returns this
Date as a millisecond value. |
int |
getTimezoneOffset()
Deprecated.
use
(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / 60000 |
int |
getYear()
Deprecated.
use
Calendar.get(Calendar.YEAR) - 1900 |
int |
hashCode()
Returns an integer hash code for the receiver.
|
static long |
parse(String string)
Deprecated.
use
DateFormat |
void |
setDate(int day)
Deprecated.
use
Calendar.set(Calendar.DATE, day) |
void |
setHours(int hour)
Deprecated.
use
Calendar.set(Calendar.HOUR_OF_DAY, hour) |
void |
setMinutes(int minute)
Deprecated.
use
Calendar.set(Calendar.MINUTE, minute) |
void |
setMonth(int month)
Deprecated.
use
Calendar.set(Calendar.MONTH, month) |
void |
setSeconds(int second)
Deprecated.
use
Calendar.set(Calendar.SECOND, second) |
void |
setTime(long milliseconds)
Sets this
Date to the specified millisecond value. |
void |
setYear(int year)
Deprecated.
use
Calendar.set(Calendar.YEAR, year + 1900) |
String |
toGMTString()
Deprecated.
use
DateFormat |
String |
toLocaleString()
Deprecated.
use
DateFormat |
String |
toString()
Returns a string representation of this
Date . |
static long |
UTC(int year,
int month,
int day,
int hour,
int minute,
int second)
Deprecated.
use:
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
cal.set(year + 1900, month, day, hour, minute, second);
cal.getTime().getTime(); |
public Date()
Date
instance to the current time.@Deprecated public Date(int year, int month, int day)
GregorianCalendar.GregorianCalendar(int, int, int)
Date
initialized to midnight in the default TimeZone
on
the specified date.year
- the year, 0 is 1900.month
- the month, 0 - 11.day
- the day of the month, 1 - 31.@Deprecated public Date(int year, int month, int day, int hour, int minute)
GregorianCalendar.GregorianCalendar(int, int, int, int, int)
Date
initialized to the specified date and time in the
default TimeZone
.year
- the year, 0 is 1900.month
- the month, 0 - 11.day
- the day of the month, 1 - 31.hour
- the hour of day, 0 - 23.minute
- the minute of the hour, 0 - 59.@Deprecated public Date(int year, int month, int day, int hour, int minute, int second)
Date
initialized to the specified date and time in the
default TimeZone
.year
- the year, 0 is 1900.month
- the month, 0 - 11.day
- the day of the month, 1 - 31.hour
- the hour of day, 0 - 23.minute
- the minute of the hour, 0 - 59.second
- the second of the minute, 0 - 59.public Date(long milliseconds)
Date
instance using the specified millisecond value. The
value is the number of milliseconds since Jan. 1, 1970 GMT.milliseconds
- the number of milliseconds since Jan. 1, 1970 GMT.@Deprecated public Date(String string)
DateFormat
Date
initialized to the date and time parsed from the
specified String.string
- the String to parse.public boolean after(Date date)
Date
is after the specified Date.date
- a Date instance to compare.true
if this Date
is after the specified Date
,
false
otherwise.public boolean before(Date date)
Date
is before the specified Date.date
- a Date
instance to compare.true
if this Date
is before the specified Date
,
false
otherwise.public Object clone()
Date
with the same millisecond value as this Date
.public int compareTo(Date date)
Date
to determine the relative
ordering.compareTo
in interface Comparable<Date>
date
- a Date
to compare against.int < 0
if this Date
is less than the specified Date
, 0
if
they are equal, and an int > 0
if this Date
is greater.public boolean equals(Object object)
Date
and returns if they are equal.
To be equal, the object must be an instance of Date
and have the same millisecond
value.equals
in class Object
object
- the object to compare with this object.true
if the specified object is equal to this Date
, false
otherwise.hashCode()
@Deprecated public int getDate()
Calendar.get(Calendar.DATE)
Date
object.@Deprecated public int getDay()
Calendar.get(Calendar.DAY_OF_WEEK)
Date
object.@Deprecated public int getHours()
Calendar.get(Calendar.HOUR_OF_DAY)
Date
object.@Deprecated public int getMinutes()
Calendar.get(Calendar.MINUTE)
Date
object.@Deprecated public int getMonth()
Calendar.get(Calendar.MONTH)
Date
object.@Deprecated public int getSeconds()
Calendar.get(Calendar.SECOND)
Date
object.public long getTime()
Date
as a millisecond value. The value is the number of
milliseconds since Jan. 1, 1970, midnight GMT.@Deprecated public int getTimezoneOffset()
(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / 60000
TimeZone
.TimeZone
.@Deprecated public int getYear()
Calendar.get(Calendar.YEAR) - 1900
Date
object.public int hashCode()
hashCode
in class Object
Date
's hash.equals(java.lang.Object)
@Deprecated public static long parse(String string)
DateFormat
String
. Many date/time formats are recognized, including IETF
standard syntax, i.e. Tue, 22 Jun 1999 12:16:00 GMT-0500string
- the String to parse.@Deprecated public void setDate(int day)
Calendar.set(Calendar.DATE, day)
Date
object.day
- the day of the month.@Deprecated public void setHours(int hour)
Calendar.set(Calendar.HOUR_OF_DAY, hour)
Date
object.hour
- the hour of the day.@Deprecated public void setMinutes(int minute)
Calendar.set(Calendar.MINUTE, minute)
Date
object.minute
- the minutes.@Deprecated public void setMonth(int month)
Calendar.set(Calendar.MONTH, month)
Date
object.month
- the month.@Deprecated public void setSeconds(int second)
Calendar.set(Calendar.SECOND, second)
Date
object.second
- the seconds.public void setTime(long milliseconds)
Date
to the specified millisecond value. The value is the
number of milliseconds since Jan. 1, 1970 GMT.milliseconds
- the number of milliseconds since Jan. 1, 1970 GMT.@Deprecated public void setYear(int year)
Calendar.set(Calendar.YEAR, year + 1900)
Date
object.year
- the year since 1900.@Deprecated public String toGMTString()
DateFormat
Date
in GMT in the format
"22 Jun 1999 13:02:00 GMT"
.@Deprecated public String toLocaleString()
DateFormat
Date
for the default Locale
.public String toString()
Date
.
The formatting is equivalent to using a SimpleDateFormat
with
the format string "EEE MMM dd HH:mm:ss zzz yyyy", which looks something
like "Tue Jun 22 13:07:00 PDT 1999". The current default time zone and
locale are used. If you need control over the time zone or locale,
use SimpleDateFormat
instead.@Deprecated public static long UTC(int year, int month, int day, int hour, int minute, int second)
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
cal.set(year + 1900, month, day, hour, minute, second);
cal.getTime().getTime();
year
- the year, 0 is 1900.month
- the month, 0 - 11.day
- the day of the month, 1 - 31.hour
- the hour of day, 0 - 23.minute
- the minute of the hour, 0 - 59.second
- the second of the minute, 0 - 59.