|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Date
ariba.util.core.Date
public class Date
The Date
class implements helper functions on top of
the java.util.Date
class. This also has the
flexibility to represent a calendar date which is a date/time
representation independent of timezone when used with the Ariba
Formatter classes. For example a calendar date representing 7:30
AM, Friday July 9th 1999 will appear as such independent of the
timezone the client inspecting the date is in.
The Date object using and not using the calendar date flag are not interchangeable in all cases. For example you may not change the metadata layer to use a calendar date unless the code is also aware of the change. Calendar dates are not fully supported in this release and are only intended to be used with any time cards or expense report modules.
Field Summary | |
---|---|
static java.lang.String |
ClassName
Our class name. |
static long |
DaysPerWeek
Constant for number of days in a week. |
static long |
HoursPerDay
Constant for number of hours in a day. |
static long |
MillisPerDay
Constant for number of milliseconds per day. |
static long |
MillisPerHour
Constant for number of milliseconds per hour. |
static long |
MillisPerMinute
Constant for number of milliseconds per minute. |
static long |
MillisPerSecond
Constant for number of milliseconds per second. |
static long |
MillisPerWeek
Constant for number of milliseconds per week. |
static long |
MinutesPerHour
Constant for number of minutes per hour. |
static long |
SecondsPerMinute
Constant for number of seconds per minute. |
Constructor Summary | |
---|---|
Date()
Creates a new Date for the current date and time. |
|
Date(boolean calendarDate)
Creates a new Date for the current date and
time. |
|
Date(Date other)
Creates a new Date from an existing Date
object. |
|
Date(int year,
int month,
int day)
Creates a new Date for the given year, month, and day. |
|
Date(int year,
int month,
int day,
boolean calendarDate)
Creates a new Date for the given year, month, and day. |
|
Date(int year,
int month,
int day,
boolean calendarDate,
java.util.TimeZone tz,
java.util.Locale locale)
Creates a new Date for the given year, month, and day. |
|
Date(int year,
int month,
int day,
int h,
int m,
boolean calendarDate,
java.util.TimeZone tz,
java.util.Locale locale)
Creates a new Date for the given year, month, and day. |
|
Date(long time)
Creates a new Date with the given timestamp. |
|
Date(long time,
boolean calendarDate)
Creates a new Date with the given timestamp. |
Method Summary | |
---|---|
static void |
addDays(Date date,
double daysToAdd)
Adds a specified number of days to the given Date . |
static void |
addDays(Date date,
int daysToAdd)
Adds a specified number of days to the given Date . |
static void |
addDays(Date date,
int daysToAdd,
java.util.TimeZone tz,
java.util.Locale locale)
Adds a specified number of days to the given Date . |
static void |
addMinutes(Date date,
int minutesToAdd)
Adds a specified number of minutes to the given Date . |
static void |
addMonths(Date date,
int monthsToAdd)
Adds a specified number of months to the given Date . |
static void |
addMonths(Date date,
int monthsToAdd,
java.util.TimeZone tz,
java.util.Locale locale)
Adds a specified number of months to the given Date, TimeZone and Locale . |
static void |
addYears(Date date,
int yearsToAdd)
Adds a specified number of years to the given Date . |
static void |
addYears(Date date,
int yearsToAdd,
java.util.TimeZone tz,
java.util.Locale locale)
Adds a specified number of years to the given Date, TimeZone, and Locale . |
boolean |
before(long when)
Returns true if this Date is before the given timestamp
in milliseconds. |
boolean |
between(Date from,
Date to)
Returns true if this Date is between the 2
timestamps in milliseconds. |
boolean |
between(long from,
long to)
Returns true if this Date is between the 2
timestamps in milliseconds. |
boolean |
calendarDate()
Returns true if this Date is a calendarDate |
static java.util.TimeZone |
createTimeZoneFromOffset(int minuteOffset)
Creates and returns a TimeZone for the given
minuteOffset |
int |
getDate()
Deprecated. replaced by static getDayOfMonth |
int |
getDay()
Deprecated. replaced by static getDayOfWeek |
static int |
getDayOfMonth(Date date)
Returns a one-based number which represents the day of month (assuming a Gregorian calendar) for the given Date . |
static int |
getDayOfMonth(java.util.Date date,
java.util.TimeZone tz,
java.util.Locale locale)
Returns a one-based number which represents the day of month (assuming a Gregorian calendar) for the given Date . |
static int |
getDayOfWeek(Date date)
Returns a one-based number which represents the day of the week (assuming a Gregorian calendar) for the given Date . |
static int |
getDayOfWeek(Date date,
java.util.TimeZone tz,
java.util.Locale locale)
Returns a one-based number which represents the day of the week (assuming a Gregorian calendar) for the given Date . |
int |
getHours()
Deprecated. replaced by static getHours |
static int |
getHours(Date date)
Returns the hours from midnight for the given Date . |
static int |
getHours(Date date,
java.util.TimeZone tz,
java.util.Locale locale)
Returns the hours from midnight for the given Date . |
int |
getMinutes()
Deprecated. replaced by static getMinutes |
static int |
getMinutes(Date date)
Returns the minutes portion of the time for the given Date . |
static int |
getMinutes(Date date,
java.util.TimeZone tz,
java.util.Locale locale)
Returns the minutes past the hour for the given Date . |
int |
getMonth()
Deprecated. replaced by static getMonth |
static int |
getMonth(Date date)
Returns a zero-based number which represents the calendar month (assuming a Gregorian calendar) for the given Date . |
static int |
getMonth(java.util.Date date,
java.util.TimeZone tz,
java.util.Locale locale)
Returns a zero-based number which represents the calendar month (assuming a Gregorian calendar) for the given Date . |
static Date |
getNow()
Returns the current Date on the system |
int |
getSeconds()
Deprecated. replaced by static getSeconds |
static int |
getSeconds(Date date)
Returns the seconds portion of the time for the given Date . |
static java.util.TimeZone |
getTimeZoneFromOffset(int minuteOffset)
Returns a TimeZone for the given minuteOffset |
int |
getTimezoneOffset()
Deprecated. replaced by timezoneOffset |
int |
getYear()
Deprecated. replaced by static getYear |
static int |
getYear(java.util.Date date)
Returns the calendar year (assuming a Gregorian calendar) for the given Date , e.g. |
static int |
getYear(java.util.Date date,
java.util.TimeZone tz,
java.util.Locale locale)
Returns the calendar year (assuming a Gregorian calendar) for the given Date , e.g. |
boolean |
isNull()
Returns true if this Date is the special
null date value. |
Date |
makeCalendarDate()
Creates a calendar date object that represents the time and date of this Date object in its current time zone. |
static Date |
makeCalendarDateWithoutTime(Date date)
Added this helper method because ariba.util.core.Date.makeCalendarDate does not strip off the time before converting the date to a calendar date. |
static Date |
newNull()
Returns a freshly allocated, non-calendarDate date representing a null value. |
static Date |
newNull(boolean calendarDate)
Returns a freshly allocated date representing a null value. |
void |
readExternal(java.io.ObjectInput input)
Restores the contents of this Date object. |
static boolean |
sameDay(Date date1,
Date date2)
Returns true if the two Date objects are on the
same calendar day (assuming a Gregorian calendar). |
static boolean |
sameDay(Date date1,
Date date2,
java.util.TimeZone timeZone)
Returns true if the two Date objects are on the
same calendar day (assuming a Gregorian calendar). |
void |
setDate(int date)
Deprecated. replaced by static setDayOfMonth(Date, int) |
void |
setDay(int day)
Deprecated. replaced by static setDayOfWeek(Date, int) |
static void |
setDayOfMonth(Date date,
int dayOfMonth)
Sets the day of month (assuming a Gregorian calendar) for the given Date . |
static void |
setDayOfMonth(Date date,
int dayOfMonth,
java.util.TimeZone tz,
java.util.Locale locale)
Sets the day of month (assuming a Gregorian calendar) for the given Date, TimeZone and Locale . |
static void |
setDayOfWeek(Date date,
int dayOfWeek)
Sets the day of the week (assuming a Gregorian calendar) for the given Date . |
static void |
setDayOfWeek(Date date,
int dayOfWeek,
java.util.TimeZone tz,
java.util.Locale locale)
Sets the day of the week (assuming a Gregorian calendar) for the given Date, TimeZone, and Locale . |
static void |
setHours(Date date,
int hours)
Sets the hours from midnight for the given Date . |
static void |
setHours(Date date,
int hours,
java.util.TimeZone tz,
java.util.Locale locale)
Sets the hours from midnight for the given Date, TimeZone and Locale . |
void |
setHours(int hours)
Deprecated. replaced by static setHours(Date, int) |
static void |
setHoursMinutesSeconds(Date date,
Date time)
Sets the number of hours, minutes, and seconds past midnight for the given Date . |
static void |
setHoursMinutesSeconds(Date date,
int h,
int m,
int s)
Sets the number of hours, minutes, and seconds past midnight for the given Date . |
static void |
setHoursMinutesSeconds(Date date,
int h,
int m,
int s,
java.util.TimeZone timeZone)
Sets the number of hours, minutes, and seconds past midnight for the given Date and TimeZone . |
static void |
setMinutes(Date date,
int minutes)
Sets the minutes portion of the time for the given Date . |
static void |
setMinutes(Date date,
int minutes,
java.util.TimeZone tz,
java.util.Locale locale)
Sets the minutes portion of the time for the given Date . |
void |
setMinutes(int minutes)
Deprecated. replaced by static setMinutes(Date, int) |
static void |
setMonth(Date date,
int month)
Sets the calendar month (assuming a Gregorian calendar) for the given Date . |
static void |
setMonth(Date date,
int month,
java.util.TimeZone tz,
java.util.Locale locale)
Sets the calendar month (assuming a Gregorian calendar) for the given Date, TimeZone and Locale . |
void |
setMonth(int month)
Deprecated. replaced by static setMonth(Date, int) |
static void |
setSeconds(Date date,
int seconds)
Sets the seconds portion of the time for the given Date . |
void |
setSeconds(int seconds)
Deprecated. replaced by static setSeconds(Date, int) |
static void |
setTimeToMidnight(Date date)
Sets the hours, minutes, and seconds past midnight for the given Date to zero. |
static void |
setTimeToMidnight(Date date,
java.util.TimeZone tz)
Sets the hours, minutes, and seconds past midnight for the given Date to zero. |
static void |
setYear(Date date,
int year)
Sets the calendar year (assuming a Gregorian calendar) for the given Date . |
static void |
setYear(Date date,
int year,
java.util.TimeZone tz,
java.util.Locale locale)
Sets the calendar year (assuming a Gregorian calendar) for the given Date, TimeZone, and Locale . |
void |
setYear(int year)
Deprecated. replaced by static setYear(Date, int) |
static boolean |
timeIsMidnight(Date date)
Returns true if the hours, minutes, and seconds past midnight for the given Date are all zero, i.e. |
static boolean |
timeIsMidnight(Date date,
java.util.TimeZone timeZone)
Returns true if the hours, minutes, and seconds past midnight for the given Date are all zero, i.e. |
static int |
timezoneOffset(java.util.Date date)
Returns the time zone offset from GMT for the given Date
in minutes. |
static int |
timezoneOffset(java.util.Date date,
java.util.TimeZone tz)
Returns the time zone offset from GMT for the given Date
in minutes. |
static int |
timezoneOffsetInMillis(Date date)
Returns the time zone offset from GMT for the given Date
in milliseconds. |
static int |
timezoneOffsetInMillis(java.util.Date date)
Returns the time zone offset from GMT for the given Date
in milliseconds. |
static int |
timezoneOffsetInMillis(Date date,
java.util.TimeZone tz)
Returns the time zone offset from GMT for the given Date
in milliseconds. |
static int |
timezoneOffsetInMillis(java.util.Date date,
java.util.TimeZone tz)
Returns the time zone offset from GMT for the given Date
in milliseconds. |
java.lang.String |
toConciseDateString()
Returns a string representation of the date portion of this Date in a concise, unpadded format, e.g. |
java.lang.String |
toConciseDateTimeString()
Returns a string representation of the date and time for this Date in a concise, unpadded format, e.g. |
java.lang.String |
toDateMonthYearString()
Returns a string representation of the date portion of this Date which includes the full month, day of month and
year, e.g. |
java.lang.String |
toDayDateMonthYearString()
Returns a string representation of the date portion of this Date which includes an abbreviated day of week, day of
month, month, and year, e.g. |
java.lang.String |
toDayOfWeekString()
Returns an abbreviated string representation of the day of the week represented by this Date , e.g. |
java.lang.String |
toFileTimeString()
Returns a string representation of the time portion of this Date in a format suitable for use as a filename suffix. |
java.lang.String |
toFullDateMonthYearString()
Returns a string representation of this Date which
includes the full month, day of month, year and time, e.g. |
java.lang.String |
toFullDayDateMonthYearString()
Returns a string representation of this Date (including
time) which includes the full day of week, month, day of month, year
and time e.g. |
java.lang.String |
toGMT()
Returns a string representing this Date in a standard GMT
format, e.g. |
java.lang.String |
toGMTString()
Deprecated. replaced by toGMT |
java.lang.String |
toHourMinSecString()
Returns a string representation of the time portion of this Date which includes hours, minutes and seconds, e.g. |
java.lang.String |
toLongDayDateMonthYearString()
Returns a string representation of the date portion of this Date which includes the full day of week, month, day of
month and year, e.g. |
java.lang.String |
toMilitaryTimeString()
Returns a string representation of the time portion of this Date in military time format, e.g. |
java.lang.String |
toPaddedConciseDateString()
Returns a string representation of the date portion of this Date in a concise, padded format, e.g. |
java.lang.String |
toPaddedConciseDateTimeString()
Returns a string representation of the date and time for this Date in a concise, padded format, e.g. |
java.lang.String |
toString()
Converts this Date object to a String |
java.lang.String |
toYearMonthDate()
Returns a string representation of this Date in a compact
format with year, month, and day of month run together, e.g. |
void |
updateToBeCalendarDate(java.util.TimeZone tz)
Updates this Date to be an Ariba calendar date that represents the same day and time of day universally that this Date currently represents in the given TimeZone. |
void |
writeExternal(java.io.ObjectOutput output)
Writes the contents of this Date object. |
Methods inherited from class java.util.Date |
---|
after, before, clone, compareTo, equals, getTime, hashCode, parse, setTime, toLocaleString, UTC |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ClassName
public static final long DaysPerWeek
public static final long HoursPerDay
public static final long MinutesPerHour
public static final long SecondsPerMinute
public static final long MillisPerSecond
public static final long MillisPerMinute
public static final long MillisPerHour
public static final long MillisPerDay
public static final long MillisPerWeek
Constructor Detail |
---|
public Date()
Date
for the current date and time.
public Date(boolean calendarDate)
Date
for the current date and
time. If calendarDate is true, a calendar date object will be
created.
If calendarDate is true, the Date object created will
represent the same time in hours, minutes, and seconds as the
current date does in the local time zone.
calendarDate
- true
if the object should be a calendarDatepublic Date(long time)
Date
with the given timestamp.
See java.lang.System.currentTimeMillis()
time
- time in millisecondspublic Date(long time, boolean calendarDate)
Date
with the given timestamp.
See java.lang.System.currentTimeMillis()
time
- time in millisecondscalendarDate
- if true
a calendar date
object will be created.
If calendarDate is true, the Date object created will
represent the same time in hours, minutes, and seconds as the
timestamp has does in the local time zone.public Date(Date other)
Date
from an existing Date
object.
other
- a Date
object to copy the time frompublic Date(int year, int month, int day)
Date
for the given year, month, and day.
year
- the year for the Gregorian calendar, e.g. 1998month
- the zero-based month (December is 11)day
- the one-based day-of-month (first of the month is 1)public Date(int year, int month, int day, boolean calendarDate)
Date
for the given year, month, and day.
year
- the year for the Gregorian calendar, e.g. 1998month
- the zero-based month (December is 11)day
- the one-based day-of-month (first of the month is 1)calendarDate
- if true
a calendar date
object will be createdpublic Date(int year, int month, int day, boolean calendarDate, java.util.TimeZone tz, java.util.Locale locale)
Date
for the given year, month, and day.
year
- the year for the Gregorian calendar, e.g. 1998month
- the zero-based month (December is 11)day
- the one-based day-of-month (first of the month is 1)calendarDate
- if true
a calendar datetz
- the TimeZone to use if calendarDate is false
locale
- the Locale for year, month, day
object will be createdpublic Date(int year, int month, int day, int h, int m, boolean calendarDate, java.util.TimeZone tz, java.util.Locale locale)
Date
for the given year, month, and day.
year
- the year for the Gregorian calendar, e.g. 1998month
- the zero-based month (December is 11)day
- the one-based day-of-month (first of the month is 1)h
- the number of hours since midnightm
- the number of minutes past the hourcalendarDate
- if true
a calendar datetz
- the TimeZone to use if calendarDate is false
locale
- the Locale for year, month, day
object will be createdMethod Detail |
---|
public static Date newNull(boolean calendarDate)
Note: the null date is actually Date(100800000) instead of Date(0) because of stupid GMT to local timezone conversion problems. It is important that all dates in the system use Date.newNull() instead of Date(0) to get starting point for all dates. Date(0) is verboten.
calendarDate
- true if the object created should be of
type calendar date
public static Date newNull()
newNull(boolean)
public boolean isNull()
true
if this Date
is the special
null date value.
newNull(boolean)
public Date makeCalendarDate()
this
is not a calendar date and has
the time 7:30 AM, Friday July 9th 1999 PDT, and the caller is
in the PDT timezone, a calendar date will be created that will
display as 7:30 AM, Friday July 9th 1999 in any timezone when
using the Ariba formatters.
To be clear, a Date does not know "its current time zone", and
this method does not allow you to pass in the user session's
TimeZone. When it says "this Date object in its current time
zone", you should read it as "this Date object in the SERVER's
time zone", which is always "America/Los_Angeles" (aka PT, PST,
PDT) in On Demand. To verify this, see timezoneOffsetInMillis,
which calls DateFormatter getDefaultTimeZone, which returns JDK
TimeZone getDefault(). See updateToBeCalendarDate(TimeZone) for
a better alternative that can handle the user session's current
time zone, or any other desired time zone.
Date
object if this is not a
calendar date object, or this
if this object is
already a calendar datepublic void updateToBeCalendarDate(java.util.TimeZone tz)
TimeZone
- if the TimeZone is null, the default host server TimeZone will be
used, but it is safer to pass an explicit TimeZone, since conversion to a calendar
date requires a contextual TimeZone for correct behavior.public static Date makeCalendarDateWithoutTime(Date date)
public java.lang.String toConciseDateString()
Date
in a concise, unpadded format, e.g. "1/12/1999".
The exact format is locale-specific.
public java.lang.String toPaddedConciseDateString()
Date
in a concise, padded format, e.g. "1/12/1999". The
exact format is locale-specific.
public java.lang.String toConciseDateTimeString()
Date
in a concise, unpadded format, e.g. "1/12/1999 3:14
PM". The exact format is locale-specific.
public java.lang.String toPaddedConciseDateTimeString()
Date
in a concise, padded format, e.g. "01/12/1999 03:14
PM". The exact format is locale-specific.
public java.lang.String toDayDateMonthYearString()
Date
which includes an abbreviated day of week, day of
month, month, and year, e.g. "Mon, 02 Jun, 1999". The exact format is
locale-specific.
public java.lang.String toLongDayDateMonthYearString()
Date
which includes the full day of week, month, day of
month and year, e.g. "Monday, January 31, 1999". The exact format is
locale-specific.
public java.lang.String toFullDayDateMonthYearString()
Date
(including
time) which includes the full day of week, month, day of month, year
and time e.g. "Monday, January 31, 1999 at 3:15 PM". The exact format
is locale-specific.
public java.lang.String toDateMonthYearString()
Date
which includes the full month, day of month and
year, e.g. "January 31, 1999". The exact format is locale-specific.
public java.lang.String toFullDateMonthYearString()
Date
which
includes the full month, day of month, year and time, e.g. "January
31, 1999 at 3:15 PM". The exact format is locale-specific.
public java.lang.String toHourMinSecString()
Date
which includes hours, minutes and seconds, e.g.
"3:01:42". The exact format is locale-specific.
public java.lang.String toDayOfWeekString()
Date
, e.g. "Mon", "Tue", etc.
public java.lang.String toString()
toString
in class java.util.Date
public java.lang.String toGMTString()
toGMT
Date
in a standard GMT
format, e.g. "12 Aug 1995 02:30:00 GMT". We override this deprecated
method but leave it marked as deprecated so any customization code
that might call this deprecated method will still get a reasonable
implementation.
toGMTString
in class java.util.Date
public java.lang.String toGMT()
Date
in a standard GMT
format, e.g. "12 Aug 1995 02:30:00 GMT". This method should be used
in place of the deprecated toGMTString
. This format is
not not locale-specific.
public java.lang.String toYearMonthDate()
Date
in a compact
format with year, month, and day of month run together, e.g.
"19990521". This format is not locale-specific.
public java.lang.String toMilitaryTimeString()
Date
in military time format, e.g. "21:05:35". This
format is not locale-specific.
public java.lang.String toFileTimeString()
Date
in a format suitable for use as a filename suffix.
public boolean calendarDate()
Date
is a calendarDate
public boolean before(long when)
Date
is before the given timestamp
in milliseconds.
when
- The number of milliseconds to compare against as
returned by getTime()
when
and
false otherwisepublic boolean between(long from, long to)
Date
is between the 2
timestamps in milliseconds. If it is the same as one
of the two, it will not be considered between, and will
return false.
from
- The number of milliseconds representing the lower
boundary of the interval.to
- The number of milliseconds representing the upper
boundary of the interval.
to
and
from
and false otherwise.public boolean between(Date from, Date to)
Date
is between the 2
timestamps in milliseconds. If it is the same as one
of the two, it will not be considered between, and will
return false.
from
- The Date
representing the lower
boundary of the interval.to
- The Date
representing the upper
boundary of the interval.
to
and
from
and false otherwise.public static Date getNow()
Date
on the system
public int getTimezoneOffset()
timezoneOffset
getTimezoneOffset
in class java.util.Date
public static int timezoneOffset(java.util.Date date)
Date
in minutes. The result is the number of minutes that should be added
to GMT time to get the locale time for the given date.
The date
parameter is a java.util.Date
, so
this method can be used with java.sql.Timestamp
, which is
a subclass of java.util.Date
.
date
- a java.util.Date
or a
ariba.util.core.Date
object that identifies the
date to use when calculating the offset.
public static int timezoneOffset(java.util.Date date, java.util.TimeZone tz)
Date
in minutes. The result is the number of minutes that should be added
to GMT time to get the locale time for the given date.
The date
parameter is a java.util.Date
, so
this method can be used with java.sql.Timestamp
, which is
a subclass of java.util.Date
.
date
- a java.util.Date
or a
ariba.util.core.Date
object that identifies the
date to use when calculating the offset.tz
- the TimeZone
that identifies Timezone the offset
should be based on. to used. If null,
DateFormatter.getDefaultTimeZone() will be used.
public static int timezoneOffsetInMillis(Date date)
Date
in milliseconds. The result is the number of milliseconds that should
be added to GMT time to get the locale time for the given date.
date
- a Date object that identifies the date to use when
calculating the offset.
public static int timezoneOffsetInMillis(Date date, java.util.TimeZone tz)
Date
in milliseconds. The result is the number of milliseconds that should
be added to GMT time to get the locale time for the given date.
date
- a Date object that identifies the date to use when
calculating the offset.tz
- the TimeZone
that identifies Timezone the offset
should be based on. to used. If null,
DateFormatter.getDefaultTimeZone() will be used.
public static int timezoneOffsetInMillis(java.util.Date date)
Date
in milliseconds. The result is the number of milliseconds that should
be added to GMT time to get the locale time for the given date.
The date
parameter is a java.util.Date
, so
this method can be used with java.sql.Timestamp
, which is
a subclass of java.util.Date
.
date
- a java.util.Date
or
ariba.util.core.Date
object that identifies the
date to use when calculating the offset.
public static int timezoneOffsetInMillis(java.util.Date date, java.util.TimeZone tz)
Date
in milliseconds. The result is the number of milliseconds that should
be added to GMT time to get the locale time for the given date.
The date
parameter is a java.util.Date
, so
this method can be used with java.sql.Timestamp
, which is
a subclass of java.util.Date
.
date
- a java.util.Date
or
ariba.util.core.Date
object that identifies the
date to use when calculating the offset.tz
- the TimeZone
that identifies Timezone the offset
should be based on. to used. If null,
DateFormatter.getDefaultTimeZone() will be used.
public static java.util.TimeZone createTimeZoneFromOffset(int minuteOffset)
TimeZone
for the given
minuteOffset
public static java.util.TimeZone getTimeZoneFromOffset(int minuteOffset)
TimeZone
for the given minuteOffset
The time zones are cached by offset number.
public int getYear()
static getYear
getYear
in class java.util.Date
public void setYear(int year)
static setYear(Date, int)
setYear
in class java.util.Date
public static int getYear(java.util.Date date)
Date
, e.g. 1999. Note that this is different than
the JDK 1.0 getYear
method, which returned the year minus
1900.
date
- The date object to return the year from.
public static int getYear(java.util.Date date, java.util.TimeZone tz, java.util.Locale locale)
Date
, e.g. 1999. Note that this is different than
the JDK 1.0 getYear
method, which returned the year minus
1900.
date
- The date object to return the year from.tz
- TimeZone of the calendarlocale
- Locale of the calendar
public static void setYear(Date date, int year)
Date
.
date
- The date object to set the year in.year
- an integer representing the year of the date
object. The year used should be a fully represented year. If
you specify 99 you will get the year 99, rather than the year
1999.public static void setYear(Date date, int year, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone, and Locale
.
date
- The date object to set the year in.year
- an integer representing the year of the date
object. The year used should be a fully represented year. If
you specify 99 you will get the year 99, rather than the year
1999.tz
- TimeZone of the calendarlocale
- Locale of the calendarpublic int getMonth()
static getMonth
getMonth
in class java.util.Date
public void setMonth(int month)
static setMonth(Date, int)
setMonth
in class java.util.Date
public static int getMonth(Date date)
Date
.
date
- the date to return the month from.
public static int getMonth(java.util.Date date, java.util.TimeZone tz, java.util.Locale locale)
Date
.
date
- the date to return the month from.tz
- TimeZone of the calendarlocale
- Locale of the calendar
public static void setMonth(Date date, int month)
Date
. The value given should be zero-based, i.e.
January = 0, December = 11.
date
- the date object to set the month in.month
- an int from 0-11 representing the month to set.public static void setMonth(Date date, int month, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone and Locale
. The value given should be zero-based, i.e.
January = 0, December = 11.
date
- the date object to set the month in.month
- an int from 0-11 representing the month to set.tz
- TimeZone of the calendarlocale
- Locale of the calendarpublic int getDate()
static getDayOfMonth
getDate
in class java.util.Date
public void setDate(int date)
static setDayOfMonth(Date, int)
setDate
in class java.util.Date
public static int getDayOfMonth(Date date)
Date
.
date
- The date object to retrieve the day of month from.
public static int getDayOfMonth(java.util.Date date, java.util.TimeZone tz, java.util.Locale locale)
Date
.
date
- The date to get the day of the month from.tz
- TimeZone of the calendarlocale
- Locale of the calendar
public static void setDayOfMonth(Date date, int dayOfMonth)
Date
. The value given should be one-based, so a value
of 1 represents the first day of the month.
date
- The date to set the day of the month in.dayOfMonth
- an int from 1-31 of the day of the monthpublic static void setDayOfMonth(Date date, int dayOfMonth, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone and Locale
. The value given should be one-based, so a value
of 1 represents the first day of the month.
date
- The date to set the day of the month in.dayOfMonth
- an int from 1-31 of the day of the monthtz
- TimeZone of the calendarlocale
- Locale of the calendarpublic int getDay()
static getDayOfWeek
getDay
in class java.util.Date
public void setDay(int day)
static setDayOfWeek(Date, int)
public static int getDayOfWeek(Date date)
Date
. This method should be used with caution as
different locales determine different days as the first day of
the week.
date
- the date to return the day of the week from.
public static int getDayOfWeek(Date date, java.util.TimeZone tz, java.util.Locale locale)
Date
. This method should be used with caution as
different locales determine different days as the first day of
the week.
date
- the date to return the day of the week from.tz
- TimeZone of the calendarlocale
- Locale of the calendar
public static void setDayOfWeek(Date date, int dayOfWeek)
Date
. The value given should be
one-based, so a value of 1 represents the first day of the
week. This method should be used with caution as different
locales determine different days as the first day of the week.
date
- the date to set the day of the week from.dayOfWeek
- an int from 1-7 representing the day of the week.public static void setDayOfWeek(Date date, int dayOfWeek, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone, and Locale
. The value given should be
one-based, so a value of 1 represents the first day of the
week. This method should be used with caution as different
locales determine different days as the first day of the week.
date
- the date to set the day of the week from.dayOfWeek
- an int from 1-7 representing the day of the week.tz
- TimeZone of the calendarlocale
- Locale of the calendarpublic int getHours()
static getHours
getHours
in class java.util.Date
public void setHours(int hours)
static setHours(Date, int)
setHours
in class java.util.Date
public static int getHours(Date date)
Date
.
date
- The object to get the number of hours from.
public static int getHours(Date date, java.util.TimeZone tz, java.util.Locale locale)
Date
.
date
- The object to get the number of hours from.tz
- TimeZone of the calendarlocale
- Locale of the calendar
public static void setHours(Date date, int hours)
Date
.
date
- The object to set the number of hours in.hours
- The number of hours past the start of the day.public static void setHours(Date date, int hours, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone and Locale
.
date
- The object to set the number of hours in.hours
- The number of hours past the start of the day.tz
- TimeZone of the calendarlocale
- Locale of the calendarpublic int getMinutes()
static getMinutes
getMinutes
in class java.util.Date
public void setMinutes(int minutes)
static setMinutes(Date, int)
setMinutes
in class java.util.Date
public static int getMinutes(Date date)
Date
.
date
- The object to get the number of minutes from.
public static void setMinutes(Date date, int minutes)
Date
.
date
- The object to modify the number of minutes in.minutes
- The number of minutes past the hour to set.public static void setMinutes(Date date, int minutes, java.util.TimeZone tz, java.util.Locale locale)
Date
.
date
- The object to modify the number of minutes in.minutes
- The number of minutes past the hour to set.public static int getMinutes(Date date, java.util.TimeZone tz, java.util.Locale locale)
Date
.
date
- The object to get the number of hours from.tz
- TimeZone of the calendarlocale
- Locale of the calendar
public int getSeconds()
static getSeconds
getSeconds
in class java.util.Date
public void setSeconds(int seconds)
static setSeconds(Date, int)
setSeconds
in class java.util.Date
public static int getSeconds(Date date)
Date
.
date
- The object to return the number of seconds from.
public static void setSeconds(Date date, int seconds)
Date
.
date
- The object to modify the number of seconds in.seconds
- The number of seconds past the minute to set.public static void addYears(Date date, int yearsToAdd)
Date
.
date
- The Date
object to modify.yearsToAdd
- an integer of the number of years to add.public static void addYears(Date date, int yearsToAdd, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone, and Locale
.
date
- The Date
object to modify.yearsToAdd
- an integer of the number of years to add.tz
- TimeZone of the calendarlocale
- Locale of the calendarpublic static void addMonths(Date date, int monthsToAdd)
Date
.
date
- The Date
object to modify.monthsToAdd
- an integer of the number of months to add.public static void addMonths(Date date, int monthsToAdd, java.util.TimeZone tz, java.util.Locale locale)
Date, TimeZone and Locale
.
date
- The Date
object to modify.monthsToAdd
- an integer of the number of months to add.tz
- TimeZone of the calendarlocale
- Locale of the calendarpublic static void addDays(Date date, int daysToAdd)
Date
.
date
- The Date
object to modify.daysToAdd
- an integer of the number of days to add.public static void addDays(Date date, int daysToAdd, java.util.TimeZone tz, java.util.Locale locale)
Date
.
date
- The Date
object to modify.daysToAdd
- an integer of the number of days to add.tz
- TimeZone of the calendar used to add dayslocale
- Locale of the calendar used to add dayspublic static void addDays(Date date, double daysToAdd)
Date
. If you know that the time is an exact
number of days, call the method with an int instead.
date
- The Date
object to modify.daysToAdd
- a double of the number of days to add. If
fractional the time of day will also be changed rather than
just the day of the month.public static void addMinutes(Date date, int minutesToAdd)
Date
.
date
- The Date
object to modify.minutesToAdd
- an integer of the number of minutes to add.public static boolean sameDay(Date date1, Date date2)
Date
objects are on the
same calendar day (assuming a Gregorian calendar). The two
dates must either both be calendar dates or must both not be
calendar dates. This uses DateFormatter.getDefaultTimeZone to
determine the time zone.
date1
- the first Date
to comparedate2
- the second Date
to compare
true
of the given dates fall on the
same calendar day, false
otherwisepublic static boolean sameDay(Date date1, Date date2, java.util.TimeZone timeZone)
Date
objects are on the
same calendar day (assuming a Gregorian calendar). The two
dates must either both be calendar dates or must both not be
calendar dates. This version allows the caller to private a
TimeZone
date1
- the first Date
to comparedate2
- the second Date
to comparetimeZone
- the TimeZone
to use for comparison
true
of the given dates fall on the
same calendar day, false
otherwisepublic static void setHoursMinutesSeconds(Date date, Date time)
Date
. The default timezone is used to
determine when midnight occurs.
date
- the Date
to modifytime
- the Date
object that provides the hour, minute,
and second information to setpublic static void setHoursMinutesSeconds(Date date, int h, int m, int s)
Date
. The default timezone is used to
determine when midnight occurs.
date
- the Date
to modifyh
- the number of hours since midnightm
- the number of minutes past the hours
- the number of seconds past the minutepublic static void setHoursMinutesSeconds(Date date, int h, int m, int s, java.util.TimeZone timeZone)
Date
and TimeZone
.
date
- the Date
to modifyh
- the number of hours since midnightm
- the number of minutes past the hours
- the number of seconds past the minutetimeZone
- the timezone to use for determining midnightpublic static void setTimeToMidnight(Date date)
Date
to zero. The default timezone is used to determine
when midnight occurs.
date
- the Date object to clear the hours, minutes and
seconds in.public static void setTimeToMidnight(Date date, java.util.TimeZone tz)
Date
to zero.
date
- the Date object to clear the hours, minutes and
seconds in.tz
- the timezone to make the calculations for.public static boolean timeIsMidnight(Date date)
Date
are all zero, i.e. the time is midnight. We
use the default timezone to determine when midnight occurs.
date
- a date to check for 0 hours, minutes, seconds, millis
public static boolean timeIsMidnight(Date date, java.util.TimeZone timeZone)
Date
are all zero, i.e. the time is midnight,
in the given TimeZone
.
public void writeExternal(java.io.ObjectOutput output) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
output
- the stream to write the object to
java.io.IOException
- Includes any I/O exceptions that may occurpublic void readExternal(java.io.ObjectInput input) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
input
- the stream to read data from in order to restore the object
java.io.IOException
- if I/O errors occur
java.lang.ClassNotFoundException
- If the class for an object being
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |