02/28/2005
 

com.vignette.portal.util
Class DateUtils

java.lang.Object
  |
  +--com.vignette.portal.util.DateUtils

public final class DateUtils
extends Object

A set of date related utilities to supplement Calendar. This class is used by first obtaining a DateUtils instance via one of the available getInstance() methods. Whenever the time zone is known to be different than the default system time zone, the method DateUtils.getInstance(TimeZone) should be used here.


Method Summary
 int diffInDays(Date date1, Date date2)
          Determine the number of days difference between two dates.
 long diffInSecs(Date date1, Date date2)
          Determine the number of seconds between two dates.
 boolean equalsIgnoreTime(Date date1, Date date2)
          Determine if two Date objects are refering to the same day.
static DateUtils getInstance()
          Retrieve an instance of DateUtils using the default Locale and Timezone of the current server.
static DateUtils getInstance(TimeZone zone)
          Retrieve an instance of DateUtils using the default Locale of the current server and the specified Timezone.
 String getISODateStamp(Date date)
          Return a date as a date string formatted using ISO 8601 conventions.
 String getISODateTimeStamp(Date date)
          Return a date as a date and time string formatted using ISO 8601 conventions.
 boolean isToday(Date then)
          Determine if the specified Date refers to today.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DateUtils getInstance(TimeZone zone)
Retrieve an instance of DateUtils using the default Locale of the current server and the specified Timezone.
Parameters:
zone - The TimeZone to use for all operations that are TimeZone specific.
Returns:
A DateUtils instance using the specified TimeZone.

getInstance

public static DateUtils getInstance()
Retrieve an instance of DateUtils using the default Locale and Timezone of the current server.
Returns:
A DateUtils instance using the default Time Zone of the current server.

equalsIgnoreTime

public boolean equalsIgnoreTime(Date date1,
                                Date date2)
Determine if two Date objects are refering to the same day. Note that since the Dates could have been generated from two different timezones, they are only considered to refer to the same day if they have the same Year, Month, and Date at the TimeZone on which we are operating.

The comparison is relative to the TimeZone, such that for example if GMT is being used (in DateUtils.getInstance(TimeZone)) - if the first date was generated at 11pm in San Francisco (1am New York) and the second date is generated in New York at 1:30am (the "following" day) the result is true because both days are actually the same day in GMT.

Parameters:
date1 - One of two dates to be compared.
date2 - One of two dates to be compared.
Returns:
true iff both dates refer to the same Year, Month, and Date (at GMT).

isToday

public boolean isToday(Date then)
Determine if the specified Date refers to today.
Parameters:
then - The date upon which to evaluate if it's today or a different day.
Returns:
true iff the specified Date is today (in the currently used TimeZone).
See Also:
DateUtils.equalsIgnoreTime(Date, Date)

diffInDays

public int diffInDays(Date date1,
                      Date date2)
Determine the number of days difference between two dates. This is computed by calculating the number of 24 hour periods between the two dates. A negative value will be returned if the first date comes chronologically after the second date parameter. Use Math.abs(int) on the result if a positive integer is desired.
Parameters:
date1 - One side of the dfference operation.
date2 - One side of the dfference operation.
Returns:
The number of days between two dates.

diffInSecs

public long diffInSecs(Date date1,
                       Date date2)
Determine the number of seconds between two dates. This is computed by calculating the number of 1000 millisecond periods between the two dates. A negative value will be returned if the first date comes chronologically after the second date parameter. Use Math.abs(long) on the result if a positive long is desired.
Parameters:
date1 - One side of the difference operation.
date2 - One side of the difference operation.
Returns:
The number of seconds between two dates.

getISODateTimeStamp

public String getISODateTimeStamp(Date date)
Return a date as a date and time string formatted using ISO 8601 conventions. This particular format is used to optimize space while providing all date information from the year down to the millisecond.
Parameters:
date - The date to be formatted.
Returns:
An ISO 8601 format of the specified Date.

getISODateStamp

public String getISODateStamp(Date date)
Return a date as a date string formatted using ISO 8601 conventions. This particular format is used to be human readable in an internationally recognized format, providing only year, month, and day information.
Parameters:
date - The date to be formatted.
Returns:
An ISO 8601 format of the specified Date.

02/28/2005
 

Copyright and Trademark Notices