org.semanticdesktop.aperture.util
Class DateUtil

java.lang.Object
  extended by org.semanticdesktop.aperture.util.DateUtil

public class DateUtil
extends Object

Provides utility methods for handling dates.


Constructor Summary
DateUtil()
           
 
Method Summary
static String date2String(Date date)
          Format the given date in a good date format: ISO-8601, using the - seperators accordingly.
static String dateTime2String(Date date)
          Format the given date in a good dateTime format: ISO-8601, using the T separator and the - and : seperators accordingly.
static String dateTime2UTCString(Date date)
          Returns the given date formatted as an ISO 8601 dateTime string normalized to the UTC timezone.
static boolean dateTimeEqualToUTCString(Date dateTime, String utcString)
          Returns true if two dates are equal - denote the same time in milliseconds from the Epoch.
static boolean dateTimeStringEqualToUTCString(String dateTimeString, String utcString)
          Returns true if two dates are equal - denote the same time in milliseconds from the Epoch.
static DateFormat getISO8601DateFormat()
          Returns a statically shared DateFormat that uses the ISO-8601 format, which is used by XSD-DATETIME.
static DateFormat getISO8601DateFormatNoTimezone()
          Returns a statically shared DateFormat that uses the ISO-8601 format, which is used by XSD-DATETIME.
static DateFormat getPlainDateFormat()
          Returns a statically shared DateFormat that uses the ISO-8601 format, which is used by XSD-DATE
static Date string2Date(String string)
          Parses the given string as a Date using the same date format as date2String.
static Date string2DateTime(String string)
          Parses the given string as a Date using the same date format as dateTime2String.
static String string2UTCString(String string)
          Converts the string in the ISO-8601 dateTime format to a string representing the same timestamp, normalized to the UTC timezone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtil

public DateUtil()
Method Detail

dateTime2String

public static String dateTime2String(Date date)
Format the given date in a good dateTime format: ISO-8601, using the T separator and the - and : seperators accordingly. Example: 2003-01-22T17:00:00+01:00.

Parameters:
date - A date instance.
Returns:
A String containing the date in ISO-8601 format.
See Also:
string2DateTime(String)

date2String

public static String date2String(Date date)
Format the given date in a good date format: ISO-8601, using the - seperators accordingly. Example: 2003-01-22

Parameters:
date - A date instance.
Returns:
A String containing the date in ISO-8601 format.
See Also:
string2Date(String)

string2DateTime

public static Date string2DateTime(String string)
                            throws ParseException
Parses the given string as a Date using the same date format as dateTime2String.

Parameters:
string - A String in ISO-8601 format.
Returns:
A Date instance with a timestamp obtained from the specified String.
Throws:
ParseException - when the specified string did not conform to the ISO-8601 standard.
See Also:
dateTime2String(Date)

string2Date

public static Date string2Date(String string)
                        throws ParseException
Parses the given string as a Date using the same date format as date2String.

Parameters:
string - A String in ISO-8601 date format.
Returns:
A Date instance with the date obtained from the specified String.
Throws:
ParseException - when the specified string did not conform to the ISO-8601 standard.
See Also:
date2String(Date)

string2UTCString

public static String string2UTCString(String string)
                               throws ParseException
Converts the string in the ISO-8601 dateTime format to a string representing the same timestamp, normalized to the UTC timezone.

Parameters:
string -
Returns:
a normalized version of the input date
Throws:
ParseException

dateTime2UTCString

public static String dateTime2UTCString(Date date)
Returns the given date formatted as an ISO 8601 dateTime string normalized to the UTC timezone.

Parameters:
date -
Returns:
a normalized version of the input date

dateTimeStringEqualToUTCString

public static boolean dateTimeStringEqualToUTCString(String dateTimeString,
                                                     String utcString)
                                              throws ParseException
Returns true if two dates are equal - denote the same time in milliseconds from the Epoch.

Parameters:
dateTimeString - a string in valid full (date + time) ISO8601 format, in any timezone
utcString - a string in valid full (date + time) ISO8601 format in the UTC timezone
Returns:
true if both strings denote equal dates
Throws:
ParseException - if the dateString format is wrong

dateTimeEqualToUTCString

public static boolean dateTimeEqualToUTCString(Date dateTime,
                                               String utcString)
Returns true if two dates are equal - denote the same time in milliseconds from the Epoch.

Parameters:
dateTime - an instance of Date
utcString - a string in valid full (date + time) ISO8601 format in the UTC timezone
Returns:
true if both strings denote equal dates
Throws:
ParseException - if the dateString format is wrong

getISO8601DateFormat

public static DateFormat getISO8601DateFormat()
Returns a statically shared DateFormat that uses the ISO-8601 format, which is used by XSD-DATETIME. This method returns the format with the timezone suffix.

Returns:
the DateFormat

getISO8601DateFormatNoTimezone

public static DateFormat getISO8601DateFormatNoTimezone()
Returns a statically shared DateFormat that uses the ISO-8601 format, which is used by XSD-DATETIME. This method returns the format without the timezone suffix.

Returns:
the DateFormat

getPlainDateFormat

public static DateFormat getPlainDateFormat()
Returns a statically shared DateFormat that uses the ISO-8601 format, which is used by XSD-DATE

Returns:
the DateFormat


Copyright © 2010 Aperture Development Team. All Rights Reserved.