ariba.util.core
Class Date

java.lang.Object
  extended by java.util.Date
      extended by ariba.util.core.Date
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Date>

public class Date
extends java.util.Date
implements java.io.Externalizable

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.

See Also:
Serialized Form

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

ClassName

public static final java.lang.String ClassName
Our class name.

See Also:
Constant Field Values

DaysPerWeek

public static final long DaysPerWeek
Constant for number of days in a week.

See Also:
Constant Field Values

HoursPerDay

public static final long HoursPerDay
Constant for number of hours in a day.

See Also:
Constant Field Values

MinutesPerHour

public static final long MinutesPerHour
Constant for number of minutes per hour.

See Also:
Constant Field Values

SecondsPerMinute

public static final long SecondsPerMinute
Constant for number of seconds per minute.

See Also:
Constant Field Values

MillisPerSecond

public static final long MillisPerSecond
Constant for number of milliseconds per second.

See Also:
Constant Field Values

MillisPerMinute

public static final long MillisPerMinute
Constant for number of milliseconds per minute.

See Also:
Constant Field Values

MillisPerHour

public static final long MillisPerHour
Constant for number of milliseconds per hour.

See Also:
Constant Field Values

MillisPerDay

public static final long MillisPerDay
Constant for number of milliseconds per day.

See Also:
Constant Field Values

MillisPerWeek

public static final long MillisPerWeek
Constant for number of milliseconds per week.

See Also:
Constant Field Values
Constructor Detail

Date

public Date()
Creates a new Date for the current date and time.


Date

public Date(boolean calendarDate)
Creates a new 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.

Parameters:
calendarDate - true if the object should be a calendarDate

Date

public Date(long time)
Creates a new Date with the given timestamp. See java.lang.System.currentTimeMillis()

Parameters:
time - time in milliseconds

Date

public Date(long time,
            boolean calendarDate)
Creates a new Date with the given timestamp. See java.lang.System.currentTimeMillis()

Parameters:
time - time in milliseconds
calendarDate - 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.

Date

public Date(Date other)
Creates a new Date from an existing Date object.

Parameters:
other - a Date object to copy the time from

Date

public Date(int year,
            int month,
            int day)
Creates a new Date for the given year, month, and day.

Parameters:
year - the year for the Gregorian calendar, e.g. 1998
month - the zero-based month (December is 11)
day - the one-based day-of-month (first of the month is 1)

Date

public Date(int year,
            int month,
            int day,
            boolean calendarDate)
Creates a new Date for the given year, month, and day.

Parameters:
year - the year for the Gregorian calendar, e.g. 1998
month - 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 created

Date

public 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.

Parameters:
year - the year for the Gregorian calendar, e.g. 1998
month - 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
tz - the TimeZone to use if calendarDate is false
locale - the Locale for year, month, day object will be created

Date

public 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.

Parameters:
year - the year for the Gregorian calendar, e.g. 1998
month - 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 midnight
m - the number of minutes past the hour
calendarDate - if true a calendar date
tz - the TimeZone to use if calendarDate is false
locale - the Locale for year, month, day object will be created
Method Detail

newNull

public static Date newNull(boolean calendarDate)
Returns a freshly allocated date representing a null value. A null value is mostly of interest because it prints as an empty string. Thus, it can be used to indicate an empty string in a TextField that always returns a Date object.

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.

Parameters:
calendarDate - true if the object created should be of type calendar date
Returns:
a new Date object representing a null value.

newNull

public static Date newNull()
Returns a freshly allocated, non-calendarDate date representing a null value.

Returns:
a new Date object representing a null value.
See Also:
newNull(boolean)

isNull

public boolean isNull()
Returns true if this Date is the special null date value.

Returns:
true if and only if this date object represents a null date as returned by Date.newNull()
See Also:
newNull(boolean)

makeCalendarDate

public Date makeCalendarDate()
Creates a calendar date object that represents the time and date of this Date object in its current time zone. For example, if 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.

Returns:
a new Date object if this is not a calendar date object, or this if this object is already a calendar date

updateToBeCalendarDate

public 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. If this Date is already a calendar date, nothing is changed. If this Date has the special NullDateMillis value, we leave the value unchanged and just mark it to be a calendar date. Otherwise, we adjust the time milliseconds value from the given TimeZone to GMT, and mark the updated value as a calendar date. For example, if this is the non-calendar date "7:30 AM, Friday July 9th 1999 PDT" and the TimeZone "America/Los_Angeles" is passed in, then this Date will become the calendar date "7:30 AM, Friday July 9th 1999 GMT", and the time value internally will have had 7 hours worth of milliseconds subtracted from it, since PDT is GMT-7. The Ariba DateFormatter code will display the same day and time for a calendar date, regardless of the session timezone. Usually for a calendar date the time will not be displayed, but it is present internally. Often the time is set to midnight at the beginning of the desired day before being updated to be a calendar date, see setTimeToMidnight(Date,TimeZone).

Parameters:
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.

makeCalendarDateWithoutTime

public 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. Fixing CR 1-9GIM3D -adding an api makeCalendarDateWithoutTime() which will strip the time off of the date.


toConciseDateString

public java.lang.String toConciseDateString()
Returns a string representation of the date portion of this Date in a concise, unpadded format, e.g. "1/12/1999". The exact format is locale-specific.

Returns:
concise date string

toPaddedConciseDateString

public java.lang.String toPaddedConciseDateString()
Returns a string representation of the date portion of this Date in a concise, padded format, e.g. "1/12/1999". The exact format is locale-specific.

Returns:
padded concise date string

toConciseDateTimeString

public java.lang.String toConciseDateTimeString()
Returns a string representation of the date and time for this Date in a concise, unpadded format, e.g. "1/12/1999 3:14 PM". The exact format is locale-specific.

Returns:
concise date and time string

toPaddedConciseDateTimeString

public java.lang.String toPaddedConciseDateTimeString()
Returns a string representation of the date and time for this Date in a concise, padded format, e.g. "01/12/1999 03:14 PM". The exact format is locale-specific.

Returns:
padded concise date and time string

toDayDateMonthYearString

public 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. "Mon, 02 Jun, 1999". The exact format is locale-specific.

Returns:
date string with abbreviated day of week, day of month, month, and year

toLongDayDateMonthYearString

public 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. "Monday, January 31, 1999". The exact format is locale-specific.

Returns:
string with full day of week, month, day of month, and year

toFullDayDateMonthYearString

public 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. "Monday, January 31, 1999 at 3:15 PM". The exact format is locale-specific.

Returns:
string with full day of week, month, day of month, year, and time

toDateMonthYearString

public 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. "January 31, 1999". The exact format is locale-specific.

Returns:
date string with full month, day of month, and year

toFullDateMonthYearString

public java.lang.String toFullDateMonthYearString()
Returns a string representation of this 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.

Returns:
string with full month, day of month, year, and time

toHourMinSecString

public java.lang.String toHourMinSecString()
Returns a string representation of the time portion of this Date which includes hours, minutes and seconds, e.g. "3:01:42". The exact format is locale-specific.

Returns:
string with hours, minutes, and seconds

toDayOfWeekString

public java.lang.String toDayOfWeekString()
Returns an abbreviated string representation of the day of the week represented by this Date, e.g. "Mon", "Tue", etc.

Returns:
abbreviated day of the week

toString

public java.lang.String toString()
Converts this Date object to a String

Overrides:
toString in class java.util.Date
Returns:
a String in EEE MMM dd HH:mm:ss zzz yyyy format

toGMTString

public java.lang.String toGMTString()
Deprecated. replaced by toGMT

Returns a string representing this 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.

Overrides:
toGMTString in class java.util.Date

toGMT

public java.lang.String toGMT()
Returns a string representing this 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.

Returns:
string in standard GMT format

toYearMonthDate

public 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. "19990521". This format is not locale-specific.

Returns:
compact date string with year, month, and day of month run together

toMilitaryTimeString

public java.lang.String toMilitaryTimeString()
Returns a string representation of the time portion of this Date in military time format, e.g. "21:05:35". This format is not locale-specific.

Returns:
time string in military time format

toFileTimeString

public 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.

Returns:
time string for filename suffix

calendarDate

public boolean calendarDate()
Returns true if this Date is a calendarDate

Returns:
true if this date is a calendarDate

before

public boolean before(long when)
Returns true if this Date is before the given timestamp in milliseconds.

Parameters:
when - The number of milliseconds to compare against as returned by getTime()
Returns:
true if this date occurred before when and false otherwise

between

public boolean between(long from,
                       long to)
Returns true if this 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.

Parameters:
from - The number of milliseconds representing the lower boundary of the interval.
to - The number of milliseconds representing the upper boundary of the interval.
Returns:
true is this date occurred between to and from and false otherwise.

between

public boolean between(Date from,
                       Date to)
Returns true if this 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.

Parameters:
from - The Date representing the lower boundary of the interval.
to - The Date representing the upper boundary of the interval.
Returns:
true is this date occurred between to and from and false otherwise.

getNow

public static Date getNow()
Returns the current Date on the system

Returns:
a new Date object containing the time that the method was invoked.

getTimezoneOffset

public int getTimezoneOffset()
Deprecated. replaced by timezoneOffset

Overrides:
getTimezoneOffset in class java.util.Date

timezoneOffset

public static int timezoneOffset(java.util.Date date)
Returns the time zone offset from GMT for the given 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.

Parameters:
date - a java.util.Date or a ariba.util.core.Date object that identifies the date to use when calculating the offset.
Returns:
a number of minutes that this date is off from GMT timezone.

timezoneOffset

public static int timezoneOffset(java.util.Date date,
                                 java.util.TimeZone tz)
Returns the time zone offset from GMT for the given 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.

Parameters:
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.
Returns:
a number of minutes that this date is off from GMT timezone.

timezoneOffsetInMillis

public static int timezoneOffsetInMillis(Date date)
Returns the time zone offset from GMT for the given 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.

Parameters:
date - a Date object that identifies the date to use when calculating the offset.
Returns:
a number of milliseconds that this date is off from GMT timezone.

timezoneOffsetInMillis

public static int timezoneOffsetInMillis(Date date,
                                         java.util.TimeZone tz)
Returns the time zone offset from GMT for the given 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.

Parameters:
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.
Returns:
a number of milliseconds that this date is off from GMT timezone.

timezoneOffsetInMillis

public static int timezoneOffsetInMillis(java.util.Date date)
Returns the time zone offset from GMT for the given 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.

Parameters:
date - a java.util.Date or ariba.util.core.Date object that identifies the date to use when calculating the offset.
Returns:
a number of milliseconds that this date is off from GMT timezone.

timezoneOffsetInMillis

public static int timezoneOffsetInMillis(java.util.Date date,
                                         java.util.TimeZone tz)
Returns the time zone offset from GMT for the given 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.

Parameters:
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.
Returns:
a number of milliseconds that this date is off from GMT timezone.

createTimeZoneFromOffset

public static java.util.TimeZone createTimeZoneFromOffset(int minuteOffset)
Creates and returns a TimeZone for the given minuteOffset


getTimeZoneFromOffset

public static java.util.TimeZone getTimeZoneFromOffset(int minuteOffset)
Returns a TimeZone for the given minuteOffset

The time zones are cached by offset number.


getYear

public int getYear()
Deprecated. replaced by static getYear

Overrides:
getYear in class java.util.Date

setYear

public void setYear(int year)
Deprecated. replaced by static setYear(Date, int)

Overrides:
setYear in class java.util.Date

getYear

public static int getYear(java.util.Date date)
Returns the calendar year (assuming a Gregorian calendar) for the given Date, e.g. 1999. Note that this is different than the JDK 1.0 getYear method, which returned the year minus 1900.

Parameters:
date - The date object to return the year from.
Returns:
int an integer representing the yar of the date object. Unlike java's getYear, 1973 will actually be returned as 1973 (rather than 73)

getYear

public 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. 1999. Note that this is different than the JDK 1.0 getYear method, which returned the year minus 1900.

Parameters:
date - The date object to return the year from.
tz - TimeZone of the calendar
locale - Locale of the calendar
Returns:
int an integer representing the year of the date object. Unlike java's getYear, 1973 will actually be returned as 1973 (rather than 73)

setYear

public static void setYear(Date date,
                           int year)
Sets the calendar year (assuming a Gregorian calendar) for the given Date.

Parameters:
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.

setYear

public 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.

Parameters:
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 calendar
locale - Locale of the calendar

getMonth

public int getMonth()
Deprecated. replaced by static getMonth

Overrides:
getMonth in class java.util.Date

setMonth

public void setMonth(int month)
Deprecated. replaced by static setMonth(Date, int)

Overrides:
setMonth in class java.util.Date

getMonth

public static int getMonth(Date date)
Returns a zero-based number which represents the calendar month (assuming a Gregorian calendar) for the given Date.

Parameters:
date - the date to return the month from.
Returns:
an int from 0-11 representing the month of the year

getMonth

public 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.

Parameters:
date - the date to return the month from.
tz - TimeZone of the calendar
locale - Locale of the calendar
Returns:
an int from 0-11 representing the month of the year

setMonth

public static void setMonth(Date date,
                            int month)
Sets the calendar month (assuming a Gregorian calendar) for the given Date. The value given should be zero-based, i.e. January = 0, December = 11.

Parameters:
date - the date object to set the month in.
month - an int from 0-11 representing the month to set.

setMonth

public 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. The value given should be zero-based, i.e. January = 0, December = 11.

Parameters:
date - the date object to set the month in.
month - an int from 0-11 representing the month to set.
tz - TimeZone of the calendar
locale - Locale of the calendar

getDate

public int getDate()
Deprecated. replaced by static getDayOfMonth

Overrides:
getDate in class java.util.Date

setDate

public void setDate(int date)
Deprecated. replaced by static setDayOfMonth(Date, int)

Overrides:
setDate in class java.util.Date

getDayOfMonth

public static int getDayOfMonth(Date date)
Returns a one-based number which represents the day of month (assuming a Gregorian calendar) for the given Date.

Parameters:
date - The date object to retrieve the day of month from.
Returns:
an int from 1-31 of the day of the month

getDayOfMonth

public 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.

Parameters:
date - The date to get the day of the month from.
tz - TimeZone of the calendar
locale - Locale of the calendar
Returns:
an int from 1-31 of the day of the month

setDayOfMonth

public static void setDayOfMonth(Date date,
                                 int dayOfMonth)
Sets the day of month (assuming a Gregorian calendar) for the given Date. The value given should be one-based, so a value of 1 represents the first day of the month.

Parameters:
date - The date to set the day of the month in.
dayOfMonth - an int from 1-31 of the day of the month

setDayOfMonth

public 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. The value given should be one-based, so a value of 1 represents the first day of the month.

Parameters:
date - The date to set the day of the month in.
dayOfMonth - an int from 1-31 of the day of the month
tz - TimeZone of the calendar
locale - Locale of the calendar

getDay

public int getDay()
Deprecated. replaced by static getDayOfWeek

Overrides:
getDay in class java.util.Date

setDay

public void setDay(int day)
Deprecated. replaced by static setDayOfWeek(Date, int)


getDayOfWeek

public 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. This method should be used with caution as different locales determine different days as the first day of the week.

Parameters:
date - the date to return the day of the week from.
Returns:
int an int from 1-7 representing the day of the week.

getDayOfWeek

public 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. This method should be used with caution as different locales determine different days as the first day of the week.

Parameters:
date - the date to return the day of the week from.
tz - TimeZone of the calendar
locale - Locale of the calendar
Returns:
int an int from 1-7 representing the day of the week.

setDayOfWeek

public static void setDayOfWeek(Date date,
                                int dayOfWeek)
Sets the day of the week (assuming a Gregorian calendar) for the given 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.

Parameters:
date - the date to set the day of the week from.
dayOfWeek - an int from 1-7 representing the day of the week.

setDayOfWeek

public 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. 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.

Parameters:
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 calendar
locale - Locale of the calendar

getHours

public int getHours()
Deprecated. replaced by static getHours

Overrides:
getHours in class java.util.Date

setHours

public void setHours(int hours)
Deprecated. replaced by static setHours(Date, int)

Overrides:
setHours in class java.util.Date

getHours

public static int getHours(Date date)
Returns the hours from midnight for the given Date.

Parameters:
date - The object to get the number of hours from.
Returns:
The number of hours past the start of the day.

getHours

public static int getHours(Date date,
                           java.util.TimeZone tz,
                           java.util.Locale locale)
Returns the hours from midnight for the given Date.

Parameters:
date - The object to get the number of hours from.
tz - TimeZone of the calendar
locale - Locale of the calendar
Returns:
The number of hours past the start of the day.

setHours

public static void setHours(Date date,
                            int hours)
Sets the hours from midnight for the given Date.

Parameters:
date - The object to set the number of hours in.
hours - The number of hours past the start of the day.

setHours

public 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.

Parameters:
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 calendar
locale - Locale of the calendar

getMinutes

public int getMinutes()
Deprecated. replaced by static getMinutes

Overrides:
getMinutes in class java.util.Date

setMinutes

public void setMinutes(int minutes)
Deprecated. replaced by static setMinutes(Date, int)

Overrides:
setMinutes in class java.util.Date

getMinutes

public static int getMinutes(Date date)
Returns the minutes portion of the time for the given Date.

Parameters:
date - The object to get the number of minutes from.
Returns:
The number of minutes past the hour.

setMinutes

public static void setMinutes(Date date,
                              int minutes)
Sets the minutes portion of the time for the given Date.

Parameters:
date - The object to modify the number of minutes in.
minutes - The number of minutes past the hour to set.

setMinutes

public 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.

Parameters:
date - The object to modify the number of minutes in.
minutes - The number of minutes past the hour to set.

getMinutes

public static int getMinutes(Date date,
                             java.util.TimeZone tz,
                             java.util.Locale locale)
Returns the minutes past the hour for the given Date.

Parameters:
date - The object to get the number of hours from.
tz - TimeZone of the calendar
locale - Locale of the calendar
Returns:
The number of minutes past the hour.

getSeconds

public int getSeconds()
Deprecated. replaced by static getSeconds

Overrides:
getSeconds in class java.util.Date

setSeconds

public void setSeconds(int seconds)
Deprecated. replaced by static setSeconds(Date, int)

Overrides:
setSeconds in class java.util.Date

getSeconds

public static int getSeconds(Date date)
Returns the seconds portion of the time for the given Date.

Parameters:
date - The object to return the number of seconds from.
Returns:
The number of seconds past the minute.

setSeconds

public static void setSeconds(Date date,
                              int seconds)
Sets the seconds portion of the time for the given Date.

Parameters:
date - The object to modify the number of seconds in.
seconds - The number of seconds past the minute to set.

addYears

public static void addYears(Date date,
                            int yearsToAdd)
Adds a specified number of years to the given Date.

Parameters:
date - The Date object to modify.
yearsToAdd - an integer of the number of years to add.

addYears

public 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.

Parameters:
date - The Date object to modify.
yearsToAdd - an integer of the number of years to add.
tz - TimeZone of the calendar
locale - Locale of the calendar

addMonths

public static void addMonths(Date date,
                             int monthsToAdd)
Adds a specified number of months to the given Date.

Parameters:
date - The Date object to modify.
monthsToAdd - an integer of the number of months to add.

addMonths

public 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.

Parameters:
date - The Date object to modify.
monthsToAdd - an integer of the number of months to add.
tz - TimeZone of the calendar
locale - Locale of the calendar

addDays

public static void addDays(Date date,
                           int daysToAdd)
Adds a specified number of days to the given Date.

Parameters:
date - The Date object to modify.
daysToAdd - an integer of the number of days to add.

addDays

public 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.

Parameters:
date - The Date object to modify.
daysToAdd - an integer of the number of days to add.
tz - TimeZone of the calendar used to add days
locale - Locale of the calendar used to add days

addDays

public static void addDays(Date date,
                           double daysToAdd)
Adds a specified number of days to the given Date. If you know that the time is an exact number of days, call the method with an int instead.

Parameters:
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.

addMinutes

public static void addMinutes(Date date,
                              int minutesToAdd)
Adds a specified number of minutes to the given Date.

Parameters:
date - The Date object to modify.
minutesToAdd - an integer of the number of minutes to add.

sameDay

public static boolean sameDay(Date date1,
                              Date date2)
Returns true if the two 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.

Parameters:
date1 - the first Date to compare
date2 - the second Date to compare
Returns:
true of the given dates fall on the same calendar day, false otherwise

sameDay

public 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). 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

Parameters:
date1 - the first Date to compare
date2 - the second Date to compare
timeZone - the TimeZone to use for comparison
Returns:
true of the given dates fall on the same calendar day, false otherwise

setHoursMinutesSeconds

public static void setHoursMinutesSeconds(Date date,
                                          Date time)
Sets the number of hours, minutes, and seconds past midnight for the given Date. The default timezone is used to determine when midnight occurs.

Parameters:
date - the Date to modify
time - the Date object that provides the hour, minute, and second information to set

setHoursMinutesSeconds

public 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. The default timezone is used to determine when midnight occurs.

Parameters:
date - the Date to modify
h - the number of hours since midnight
m - the number of minutes past the hour
s - the number of seconds past the minute

setHoursMinutesSeconds

public 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.

Parameters:
date - the Date to modify
h - the number of hours since midnight
m - the number of minutes past the hour
s - the number of seconds past the minute
timeZone - the timezone to use for determining midnight

setTimeToMidnight

public static void setTimeToMidnight(Date date)
Sets the hours, minutes, and seconds past midnight for the given Date to zero. The default timezone is used to determine when midnight occurs.

Parameters:
date - the Date object to clear the hours, minutes and seconds in.

setTimeToMidnight

public static void setTimeToMidnight(Date date,
                                     java.util.TimeZone tz)
Sets the hours, minutes, and seconds past midnight for the given Date to zero.

Parameters:
date - the Date object to clear the hours, minutes and seconds in.
tz - the timezone to make the calculations for.

timeIsMidnight

public static boolean timeIsMidnight(Date date)
Returns true if the hours, minutes, and seconds past midnight for the given Date are all zero, i.e. the time is midnight. We use the default timezone to determine when midnight occurs.

Parameters:
date - a date to check for 0 hours, minutes, seconds, millis
Returns:
true if and only if the hours, minutes, seconds, and millis are 0.

timeIsMidnight

public 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. the time is midnight, in the given TimeZone.


writeExternal

public void writeExternal(java.io.ObjectOutput output)
                   throws java.io.IOException
Writes the contents of this Date object.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
output - the stream to write the object to
Throws:
java.io.IOException - Includes any I/O exceptions that may occur

readExternal

public void readExternal(java.io.ObjectInput input)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Restores the contents of this Date object.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
input - the stream to read data from in order to restore the object
Throws:
java.io.IOException - if I/O errors occur
java.lang.ClassNotFoundException - If the class for an object being


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.