|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdanger.internal.Date
public final class Date
Date is a container for a time of day, a month, day, and year, and a time zone.
In general you will want to use java.util.Calendar instead, but you will need to convert to a Date to use DateFormat or DateTimeEditor. When converting between Calendars and Dates (since you still need to use Date for DateFormat), be warned that January is 1 here but 0 in Calendar.
Most of its operations are independent of time zone, and in particular you can set the time of day to a time that does not exist because of a daylight saving transition. The time zone is only used when converting to or from a scalar time representation or when inquiring whether daylight saving is in effect at a particular moment.
The calendar side, in contrast, restricts you to dates that actually exist in the Gregorian calendar. If you try to set the date to January 32nd, you will get February 1st.
| Field Summary | |
|---|---|
static int |
SECONDS_PER_DAY
|
static int |
SECONDS_PER_HOUR
|
static int |
SECONDS_PER_MINUTE
|
| Constructor Summary | |
|---|---|
Date()
Create a new Date in the system time zone and filled in with the current date and time. |
|
Date(Date inDate)
Create a new Date whose time zone, date, and time are copied from the specified Date. |
|
Date(int inUnixTimeGMT)
Create a new Date in the system time zone filled in with the date and time corresponding to the specified Unix time (the number of seconds since midnight DST, January 1, 1970). |
|
Date(int inYear,
int inMonth,
int inDay)
Create a new Date in the system time zone and filled in with midnight on the specified day. |
|
Date(int inUnixTimeGMT,
TimeZone inTZ)
Create a new Date in the specified time zone, filled in with the date and time corresponding to the specified Unix time (the number of seconds since midnight DST, January 1, 1970). |
|
Date(TimeZone inTZ)
Create a new Date in the specified time zone and filled in with the current date and time. |
|
| Method Summary | |
|---|---|
void |
addDays(int inDays)
Advance the day of the month by the specified number, possibly also affecting the month or year if the change brings the Date into the previous or next month. |
void |
addHours(int inHours)
Advance the date and time of this Date by the specified number of hours. |
void |
addMinutes(int inMinutes)
Advance the date and time of this Date by the specified number of minutes. |
void |
addMonths(int inMonths)
Advance the month of this Date by the specified number. |
void |
addSeconds(int inSeconds)
Advance the date and time of this Date by the specified number of seconds. |
void |
addYears(int inYear)
Increment the year of this Date by the specified number. |
int |
compareTo(Date inDate)
Compares this Date to another Date without regard to their time zones, only to their date and time. |
boolean |
equals(Date inDate)
Returns whether this Date contains the same date and time as another date, without regard to their time zones. |
boolean |
equals(Object obj)
Returns whether obj is a Date that contains the same date and time as this date, without regard to their time zones. |
String |
get12HourString()
Return a String representing the hours component, modulo 12, of this Date's time of day. |
String |
getAMPMString()
Return a locale-specific String indicating whether the time of day represented by this Date is before or after noon. |
int |
getDangerTimeGMT()
Return the number of seconds since 12:00 am GMT, January 1, 2000, that this Date's day, month, year, and time represent, taking the Date's time zone into account. |
int |
getDangerTimeLocal()
Return the number of seconds since 12:00 am GMT, January 1, 2000, that this Date's day, month, year, and time represent, ignoring the Date's time zone and acting as if it were set to GMT. |
int |
getDay()
Return the day (1-31) of the month from this Date's date. |
int |
getDayOfWeek()
Return the day of the week as a number from 0-6. |
int |
getDayOfWeekFromSunday()
Return the day of the week as a number from 0-6 assuming Sunday is 0, and Saturday is 6. |
int |
getDaysBetween(Date inDate)
Return the number of days between the specified date and this date. |
int |
getDaysInMonth()
Return the number of days in this Date's month. |
String |
getDayString()
Return a locale-specific String for the name of the day of the week of this Date. |
static String |
getDayString(int dayOfWeek)
Return a locale-specific String for the name of the specified day of the week. |
String |
getEraString()
Return a locale-specific String indicating whether or not the year represented by this Date is 1 or greater. |
int |
getHours()
Return the number of hours (0-23) from this Date's time of day. |
int |
getMaxDaysInMonth()
Return the largest number of days that this Date's month can ever have. |
int |
getMinutes()
Return the number of minutes (0-59) from this Date's time of day. |
String |
getMinutesString()
Return a two-character-long String (padded with a 0 if necessary) representing the minutes component of this Date's time of day. |
int |
getMonth()
Return the month (1-12) from this Date's date. |
String |
getMonthString()
Return a locale-specific String for the name of the month of this Date. |
static String |
getMonthString(int inMonth)
Return a locale-specific String for the name of the specified month. |
int |
getOrdinalDayOfMonth()
Returns an integer representing the Nth weekday of the month of this date ex.: A date of (2001/4/17) returns 3, since that is the 3rd Tuesday of April |
int |
getSeconds()
Return the number of seconds (0-59) from this Date's time of day. |
String |
getSecondsString()
Return a two-character-long String (padded with a 0 if necessary) representing the seconds component of this Date's time of day. |
String |
getShortDayString()
Return a locale-specific String for the name of the day of the week of this Date. |
static String |
getShortDayString(int dayOfWeek)
Return a locale-specific String for the name of the specified day of the week. |
String |
getShortMonthString()
Return a locale-specific String for the name of the month of this Date. |
static String |
getShortMonthString(int inMonth)
Return a locale-specific String for the name of the specified month. |
String |
getShortYearString()
Return a String representing this Date's year, truncated to at most two digits. |
int |
getTime()
Return this Date's time of day. |
TimeZone |
getTimeZone()
Return this time zone of this date. |
int |
getTimeZoneOffset()
Return the offset from GMT (in seconds) of this Date's time zone at the moment that it expresses. |
int |
getUnixTimeGMT()
Return the number of seconds since 12:00 am GMT, January 1, 1970, that this Date's day, month, year, and time represent, taking the Date's time zone into account. |
int |
getUnixTimeLocal()
Return the number of seconds since 12:00 am GMT, January 1, 1970, that this Date's day, month, year, and time represent, ignoring the Date's time zone and acting as if it were set to GMT. |
int |
getYear()
Return the year from this Date's date. |
int |
hashCode()
|
boolean |
inDaylightTime()
Returns whether the date should be in daylight saving time. |
boolean |
isLeapYear()
Return whether this Date's year is a leap year. |
boolean |
isSameDay(Date inDate)
Returns whether this Date is the same day (but possibly at a different time) as the specified Date. |
void |
set(Date inDate)
Set the time zone, date, and time of this Date to match those of the specified Date. |
void |
set(int inYear,
int inMonth,
int inDay)
Set the day, month, and year of this Date to match the specified values, and set the time to midnight (of this Date's time zone). |
void |
setDangerTimeGMT(int inTime)
Set the day, month, year, and time of this Date to correspond to the specified number of seconds since 12:00 am GMT, January 1, 2000, taking the Date's time zone into account. |
void |
setDangerTimeLocal(int inRefTime)
Set the day, month, year, and time of this Date to correspond to the specified number of seconds since 12:00 am GMT, January 1, 2000, ignoring the Date's time zone and acting as if it were set to GMT. |
void |
setDay(int inDay)
Set the day of the month to the specified number. |
void |
setHours(int inHours)
Set the hours component of this Date's time to the specified value. |
void |
setLocale(String s)
Sets the locale for DateFormats derived from this Date. |
void |
setMinutes(int inMinutes)
Set the minutes component of this Date's time to the specified value (0-59). |
void |
setMonth(int inMonth)
Set the month of this Date to the specified number. |
void |
setSeconds(int inSeconds)
Set the seconds component of this Date's time to the specified value (0-59). |
void |
setTime(int inTime)
Sets the time of day. |
void |
setTime(int inHours,
int inMinutes,
int inSeconds)
Set the time of day of this Date to the specified hours, minutes, and seconds. |
void |
setTimeZone(TimeZone inTZ)
Set the time zone of this date. |
void |
setToday()
Set the day, month, year, and time of this Date to match those returned by the hardware clock. |
void |
setToday(TimeZone inTZ)
Set the time zone of this Date to the specified zone and then fill in the day, month, year, and time with those returned by the hardware clock. |
void |
setUnixTimeGMT(int inTime)
Set the day, month, year, and time of this Date to correspond to the specified number of seconds since 12:00 am GMT, January 1, 1970, taking the Date's time zone into account. |
void |
setUnixTimeLocal(int inRefTime)
Set the day, month, year, and time of this Date to correspond to the specified number of seconds since 12:00 am GMT, January 1, 1970, ignoring the Date's time zone and acting as if it were set to GMT. |
void |
setYear(int inYear)
Set the year of this Date to the specified number. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int SECONDS_PER_MINUTE
public static final int SECONDS_PER_HOUR
public static final int SECONDS_PER_DAY
| Constructor Detail |
|---|
public Date()
public Date(TimeZone inTZ)
public Date(int inYear,
int inMonth,
int inDay)
public Date(int inUnixTimeGMT)
public Date(int inUnixTimeGMT,
TimeZone inTZ)
public Date(Date inDate)
| Method Detail |
|---|
public void set(Date inDate)
public void set(int inYear,
int inMonth,
int inDay)
public void setTimeZone(TimeZone inTZ)
public TimeZone getTimeZone()
public int getTimeZoneOffset()
public void setToday()
public void setToday(TimeZone inTZ)
public void setDangerTimeGMT(int inTime)
So if the time zone is set to GMT, 0 will yield 12:00 am, January 1, 2000, while if the time zone is set to Pacific time, 0 will yield 4:00 pm, December 31, 1999.
public int getDangerTimeGMT()
So if the date contains 12:00 am, January 1, 2000, if the time zone is set to GMT the return value will be 0, but if the time zone is set to Pacific time, the return value will be 28800.
Note: Dates prior to 12/13/1931 or after 1/19/2068 can not properly be returned by this method, as the number of seconds can not be represented by an integer. In this case, this method will throw a DateOutOfRangeException.
public void setDangerTimeLocal(int inRefTime)
So 0 will yield 12:00 am, January 1, 2000 no matter what the time zone is set to.
public int getDangerTimeLocal()
So if the date contains 12:00 am, January 1, 2000, the return value will be 0 no matter what the time zone is set to.
Note: Dates prior to 12/13/1931 or after 1/19/2068 can not properly be returned by this method, as the number of seconds can not be represented by an integer. In this case, this method will throw a DateOutOfRangeException.
public void setUnixTimeGMT(int inTime)
So if the time zone is set to GMT, 0 will yield 12:00 am, January 1, 1970, while if the time zone is set to Pacific time, 0 will yield 4:00 pm, December 31, 1969.
public int getUnixTimeGMT()
So if the date contains 12:00 am, January 1, 1970, if the time zone is set to GMT the return value will be 0, but if the time zone is set to Pacific time, the return value will be 28800.
Note: Dates prior to 12/14/1901 or after 1/18/2038 can not properly be returned by this method, as the number of seconds can not be represented by an integer. In this case, this method will throw a DateOutOfRangeException.
public void setUnixTimeLocal(int inRefTime)
So 0 will yield 12:00 am, January 1, 1970 no matter what the time zone is set to.
public int getUnixTimeLocal()
So if the date contains 12:00 am, January 1, 1970, the return value will be 0 no matter what the time zone is set to.
Note: Dates prior to 12/14/1901 or after 1/18/2038 can not properly be returned by this method, as the number of seconds can not be represented by an integer. In this case, this method will throw a DateOutOfRangeException.
public void setLocale(String s)
public boolean inDaylightTime()
public boolean isSameDay(Date inDate)
public boolean equals(Date inDate)
public boolean equals(Object obj)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic int compareTo(Date inDate)
public int getSeconds()
public int getMinutes()
public int getHours()
public int getDay()
public int getMonth()
public int getYear()
public int getTime()
public void setSeconds(int inSeconds)
public void addSeconds(int inSeconds)
public void setMinutes(int inMinutes)
public void addMinutes(int inMinutes)
public void setHours(int inHours)
public void addHours(int inHours)
public void setDay(int inDay)
public void addDays(int inDays)
public void setMonth(int inMonth)
public void addMonths(int inMonths)
public void setYear(int inYear)
public void addYears(int inYear)
public void setTime(int inHours,
int inMinutes,
int inSeconds)
public void setTime(int inTime)
public boolean isLeapYear()
public String getSecondsString()
public String getMinutesString()
public String get12HourString()
public String getAMPMString()
public String getEraString()
public String getMonthString()
public static String getMonthString(int inMonth)
public String getShortMonthString()
public static String getShortMonthString(int inMonth)
public String getDayString()
public static String getDayString(int dayOfWeek)
public String getShortDayString()
public static String getShortDayString(int dayOfWeek)
public String getShortYearString()
public int getDayOfWeek()
public int getDayOfWeekFromSunday()
public int getDaysBetween(Date inDate)
public int getDaysInMonth()
public int getMaxDaysInMonth()
public int getOrdinalDayOfMonth()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||