Package org.alfresco.util
Class ISO8601DateFormat
- java.lang.Object
-
- org.alfresco.util.ISO8601DateFormat
-
@AlfrescoPublicApi public class ISO8601DateFormat extends java.lang.Object
Formatting support for ISO 8601 datessYYYY-MM-DDThh:mm:ss.sssTZD
where:- sYYYY Four-digit year with optional leading positive (+) or negative (-) sign. A negative sign indicates a year BCE. The absence of a sign or the presence of a positive sign indicates a year CE (for example, -0055 would indicate the year 55 BCE, while +1969 and 1969 indicate the year 1969 CE).
- MM Two-digit month (01 = January, etc.)
- DD Two-digit day of month (01 through 31)
- hh Two digits of hour (00 through 23)
- mm Two digits of minute (00 through 59)
- ss.sss Seconds, to three decimal places (00.000 through 59.999)
- TZD Time zone designator (either Z for Zulu, i.e. UTC, or +hh:mm or -hh:mm, i.e. an offset from UTC)
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.TimeZone
UTC_TIMEZONE
-
Constructor Summary
Constructors Constructor Description ISO8601DateFormat()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
format(java.util.Date isoDate)
Format date into ISO format (UCT0 / Zulu)static java.lang.String
formatToZulu(java.lang.String isoDate)
Normalise isoDate time to Zulu(UTC0) time-zone, removing any UTC offset.static java.util.Calendar
getCalendar()
Get a calendar object from cache for the system default timezone.static java.util.Calendar
getCalendar(java.util.TimeZone timezone)
Get a calendar object from cache.static boolean
isTimeComponentDefined(java.lang.String isoDate)
Checks whether or not the given ISO8601-formatted date-string contains a time-component instead of only the actual date.static java.util.Date
parse(java.lang.String isoDate)
Parse date from ISO formatted string.static java.util.Date
parse(java.lang.String isoDate, java.util.TimeZone timezone)
Parse date from ISO formatted string, with an explicit timezone specifiedstatic java.util.Date
parseDayOnly(java.lang.String isoDate, java.util.TimeZone timezone)
Parses the given ISO8601-formatted date-string, not taking into account the time-component.static java.util.Date
parseInternal(java.lang.String isoDate, java.util.TimeZone timezone)
Parse date from ISO formatted string, either in the specified TimeZone, or with TimeZone information taken from the date
-
-
-
Method Detail
-
getCalendar
public static java.util.Calendar getCalendar(java.util.TimeZone timezone)
Get a calendar object from cache.- Parameters:
timezone
- timezone object to indicate the timezone to be used by the returned calendar object- Returns:
- calendar object from cache or newly created (if cache is empty)
-
getCalendar
public static java.util.Calendar getCalendar()
Get a calendar object from cache for the system default timezone.- Returns:
- calendar object from cache or newly created (if cache is empty)
-
format
public static java.lang.String format(java.util.Date isoDate)
Format date into ISO format (UCT0 / Zulu)- Parameters:
isoDate
- the date to format- Returns:
- the ISO Zulu timezone formatted string
-
formatToZulu
public static java.lang.String formatToZulu(java.lang.String isoDate)
Normalise isoDate time to Zulu(UTC0) time-zone, removing any UTC offset.- Parameters:
isoDate
-- Returns:
- the ISO Zulu timezone formatted string e.g 2011-02-04T17:13:14.000+01:00 -> 2011-02-04T16:13:14.000Z
-
parse
public static java.util.Date parse(java.lang.String isoDate)
Parse date from ISO formatted string. The ISO8601 date must include TimeZone offset information- Parameters:
isoDate
- ISO string to parse- Returns:
- the date
- Throws:
AlfrescoRuntimeException
- if the parse failed
-
parse
public static java.util.Date parse(java.lang.String isoDate, java.util.TimeZone timezone)
Parse date from ISO formatted string, with an explicit timezone specified- Parameters:
isoDate
- ISO string to parsetimezone
- The TimeZone the date is in- Returns:
- the date
- Throws:
AlfrescoRuntimeException
- if the parse failed
-
parseInternal
public static java.util.Date parseInternal(java.lang.String isoDate, java.util.TimeZone timezone)
Parse date from ISO formatted string, either in the specified TimeZone, or with TimeZone information taken from the date- Parameters:
isoDate
- ISO string to parsetimezone
- The time zone, null means default time zone- Returns:
- the date
- Throws:
AlfrescoRuntimeException
- if the parse failed
-
isTimeComponentDefined
public static boolean isTimeComponentDefined(java.lang.String isoDate)
Checks whether or not the given ISO8601-formatted date-string contains a time-component instead of only the actual date.- Parameters:
isoDate
-- Returns:
- true, if time is present.
-
parseDayOnly
public static java.util.Date parseDayOnly(java.lang.String isoDate, java.util.TimeZone timezone)
Parses the given ISO8601-formatted date-string, not taking into account the time-component. The time-information for the will be reset to zero.- Parameters:
isoDate
- the day (formatted sYYYY-MM-DD) or a full date (sYYYY-MM-DDThh:mm:ss.sssTZD)timezone
- the timezone to use- Returns:
- the parsed date
- Throws:
AlfrescoRuntimeException
- if the parsing failed.
-
-