Class DateFormatter
java.lang.Object
com.emc.documentum.rest.format.date.DateFormatter
This class is used for formatting/parsing date time according to ISO 8601.
We allow any ISO 8601 compliant date to be used as input for our service, and will format all outgoing dates according to RFC 3339, which is a profile of ISO 8601
This class is thread safe.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
now()
Return a RFC 3339 date string representing the current timestatic Date
Parse an ISO 8601 compliant date string into a Date object If a date without time zone offset is provided, time zone UTC (offset zero) will be assumed instead of local time zone.static Date
Parse a ISO 8601 compliant date string into a Date object If a date without time zone offset is provided, time zone specified bytimeZoneStr
will be assumed instead of local time zone.static String
Server will format the date time according to RFC 3339, http://tools.ietf.org/html/rfc3339#page-8 Atom syndication format requires date to be formatted with RFC 3339 According to RFC 3339, a colon will be used as delimiter in time zone offsettime-numoffset = ("+" / "-") time-hour ":" time-minute
static String
Server will format the date time based ontimeZoneStr
according to RFC 3339, http://tools.ietf.org/html/rfc3339#page-8.static String
Server will format the date time based ontimeZoneStr
andpattern
complying with http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html.static Date
Try to parse an ISO 8601 compliant date string into a Date object If a date without time zone offset is provided, time zone UTC (offset zero) will be assumed instead of local time zone.
-
Field Details
-
GMT_ID
-
PATTERN_RFC_3339
- See Also:
-
ISO_8601_DATE_PARSER
public static final org.joda.time.format.DateTimeFormatter ISO_8601_DATE_PARSER -
RFC_3339_FORMATTER
public static final org.joda.time.format.DateTimeFormatter RFC_3339_FORMATTER
-
-
Method Details
-
print
Server will format the date time according to RFC 3339, http://tools.ietf.org/html/rfc3339#page-8 Atom syndication format requires date to be formatted with RFC 3339 According to RFC 3339, a colon will be used as delimiter in time zone offsettime-numoffset = ("+" / "-") time-hour ":" time-minute
- Parameters:
date
- a Date instance- Returns:
- null if the date is null, otherwise a string compliant with RFC 3339 for the provided date
-
print
Server will format the date time based ontimeZoneStr
according to RFC 3339, http://tools.ietf.org/html/rfc3339#page-8. Atom syndication format requires date to be formatted with RFC 3339 According to RFC 3339, a colon will be used as delimiter in time zone offsettime-numoffset = ("+" / "-") time-hour ":" time-minute
Here is a sample.DateFormatter.print(date, "Europe/Paris");
date is 2015-09-04T02:43:03.118+08:00 The output is "2015-09-03T20:43:03.118+02:00"- Parameters:
date
- a Date instancetimeZoneStr
- time zone string. If it is invalid, UTC will be adopted.- Returns:
- null if the date is null, otherwise a string compliant with RFC 3339 for the provided date
-
print
Server will format the date time based ontimeZoneStr
andpattern
complying with http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html. The format is not limited to RFC 3339 E.G., time zone offset can be in such formats: -0800; -08:00; America/Los_Angeles Here is a sample.DateFormatter.print(date, "Europe/Paris", "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
date is 2015-09-04T02:43:03.118+08:00 The output is "2015-09-03T20:43:03.118+0200"- Parameters:
date
- a Date instancetimeZoneStr
- time zone string. If it is invalid, UTC will be adopted.pattern
- the date format pattern supported byDateTimeFormat
, not limited to RFC 3339- Returns:
- null if the date is null, otherwise a string compliant with RFC 3339 for the provided date
-
now
Return a RFC 3339 date string representing the current time- Returns:
- a RFC 3339 date string representing the current time
-
parse
Parse an ISO 8601 compliant date string into a Date object If a date without time zone offset is provided, time zone UTC (offset zero) will be assumed instead of local time zone.- Parameters:
date
- a string that is compliant with ISO 8601- Returns:
- a Date object parsed from the date string provided
-
tryParse
Try to parse an ISO 8601 compliant date string into a Date object If a date without time zone offset is provided, time zone UTC (offset zero) will be assumed instead of local time zone. If date format is not ISO 8601, or fail to parse, the current date will be returned.- Parameters:
date
- a string that is compliant with ISO 8601- Returns:
- a Date object parsed from the date string provided
-
parse
Parse a ISO 8601 compliant date string into a Date object If a date without time zone offset is provided, time zone specified bytimeZoneStr
will be assumed instead of local time zone. Here are two samples.DateFormatter.parse("2015-09-04T02:43:03.118+05:00", "GMT+3");
The output is 2015-09-04T02:43:03.118+05:00DateFormatter.parse("2015-09-04T02:43:03.118", "GMT+3");
The output is 2015-09-04T02:43:03.118+03:00- Parameters:
date
- a string that is compliant with ISO 8601timeZoneStr
- time zone string. If it is invalid, UTC will be adopted.- Returns:
- a Date object parsed from the date string provided
-