java.util
Class Date
java.lang.Object
|
+--java.util.Date
All Implemented Interfaces:
Cloneable, Comparable, Serializable
This class represents a specific time in milliseconds since the epoch.
The epoch is 1970, January 1 00:00:00.0000 UTC.
Date is intended to reflect universal time coordinate (UTC), but doesn't
handle the leap seconds.
Prior to jdk 1.1 this class was the sole Time class and had also
calendar functionality. But this can't be localized, so a new Calendar
class was created, that you should use instead. The functions which
get or return a year, month, day etc. are all deprecated and shouldn't be
used. Use Calendar instead.
Authors:- Jochen Hoenicke
- Per Bothner <bothner@cygnus.com>
See Also:
Date()
|
Date(long time)
|
Date(int year, int month, int day)
|
Date(int year, int month, int day, int hour, int min)
|
Date(int year, int month, int day, int hour, int min, int sec)
|
Date(java.lang.String s)
|
Date
public Date()
Creates a new Date Object representing the current time.
Date
public Date(int year, int month, int day)
Creates a new Date Object representing the given time.
Parameters:
Date
public Date(int year, int month, int day, int hour, int min)
Creates a new Date Object representing the given time.
Parameters:
Date
public Date(int year, int month, int day, int hour, int min, int sec)
Parameters:
Date
public Date(java.lang.String s)
Creates a new Date from the given string representation. This
does the same as new Date(Date.parse(s))
Parameters:
See Also:
Date
public Date(long time)
Creates a new Date Object representing the given time.
Parameters:
UTC
public static long UTC(int year, int month, int date, int hrs, int min, int sec)
Parameters:
Returns:
- the time in millis since the epoch.
after
public boolean after(java.util.Date when)
Tests if this date is after the specified date.
Parameters:
Returns:
- true, if the date represented by this Object is
strictly later than the time represented by when.
before
public boolean before(java.util.Date when)
Tests if this date is before the specified date.
Parameters:
Returns:
- true, if the date represented by when is strictly later
than the time represented by this object.
clone
public Object clone()
compareTo
public int compareTo(java.lang.Object obj)
Compares this Date to another. This behaves like
compareTo(Date)
, but it may throw a
ClassCastException
Parameters:
Returns:
- 0, if the date represented
by obj is exactly the same as the time represented by this
object, a negative if this Date is before the other Date, and
a positive value otherwise.
Throws:
compareTo
public int compareTo(java.util.Date when)
Compares two dates.
Parameters:
Returns:
- 0, if the date represented
by obj is exactly the same as the time represented by this
object, a negative if this Date is before the other Date, and
a positive value otherwise.
equals
public boolean equals(java.lang.Object obj)
Compares two dates for equality.
Parameters:
Returns:
- true, if obj is a Date object and the date represented
by obj is exactly the same as the time represented by this
object.
getDate
public int getDate()
Returns:
- the day of month represented by this date object.
getDay
public int getDay()
Returns:
- the day represented by this date object.
getHours
public int getHours()
Returns:
- the hours represented by this date object.
getMinutes
public int getMinutes()
Returns:
- the minutes represented by this date object.
getMonth
public int getMonth()
Returns:
- the month represented by this date object (zero based).
getSeconds
public int getSeconds()
Returns:
- the seconds represented by this date object.
getTime
public long getTime()
Gets the time represented by this Object
Returns:
- the time in milliseconds since the epoch.
getTimezoneOffset
public int getTimezoneOffset()
Returns:
- The time zone offset in minutes of the local time zone
relative to UTC. The time represented by this object is used to
determine if we should use daylight savings.
getYear
public int getYear()
Returns:
- the year minus 1900 represented by this date object.
hashCode
public int hashCode()
parse
public static long parse(java.lang.String string)
Parse a String and return the time it represents.
Parameters:
setDate
public void setDate(int date)
Sets the date to the given value, not changing the other fields.
Parameters:
setHours
public void setHours(int hours)
Sets the hours to the given value, not changing the other fields.
Parameters:
setMinutes
public void setMinutes(int minutes)
Sets the minutes to the given value, not changing the other fields.
Parameters:
setMonth
public void setMonth(int month)
Sets the month to the given value, not changing the other fields.
Parameters:
setSeconds
public void setSeconds(int seconds)
Sets the seconds to the given value, not changing the other fields.
Parameters:
setTime
public void setTime(long time)
Sets the time which this Object should represented.
Parameters:
setYear
public void setYear(int year)
Sets the year to year minus 1900, not changing the other fields.
Parameters:
toGMTString
public String toGMTString()
Format this object in a standard format in the GMT timezone.
toLocaleString
public String toLocaleString()
Format this object in a locale-specific way.
toString
public String toString()