Class ConfigurableDateFormatter
java.lang.Object
com.flowable.platform.common.util.ConfigurableDateFormatter
A configurable date / date and time formatter utility. Although the formatters can be accessed in a static way, the
configuration is done through a concrete instance of this utility class.
Make sure it is treated like a singleton, otherwise, the last configuration / instance overwrites the static values
being set before.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatInISO8601Format
(Instant instant) static String
formatInISO8601Format
(Date date) static String
formatInSimpleFormat
(Date date) static String
formatInSimpleFormatUS
(Date date) static DateTimeFormatter
static DateTimeFormatter
static DateTimeFormatter
static Instant
parseFromISO8601Format
(String date) Capable of parsing the given date string in different representations of valid ISO 8601 formatted strings.static Instant
Parses the given string formatted with UTC date time in ISO 8601 format to an Instant.protected static ZonedDateTime
parseISO8601
(String dateTimeString) ISO 8601 formats usually carry are time zone offset.static void
setSimpleFormat
(String simpleFormat) static void
setSimpleFormatUS
(String simpleFormatUS) static void
setTimeZone
(String timeZone) static void
setTimeZone
(ZoneId timeZone)
-
Constructor Details
-
ConfigurableDateFormatter
public ConfigurableDateFormatter()
-
-
Method Details
-
setSimpleFormat
-
setSimpleFormatUS
-
setTimeZone
-
setTimeZone
-
getTimeZone
-
getISO8601Formatter
-
getSimpleFormatter
-
getSimpleFormatterUS
-
parseFromISO8601Format
Capable of parsing the given date string in different representations of valid ISO 8601 formatted strings.Parseable examples:
"2020-01-01T12:00:00.000Z" // 'basic' ISO 8601 format (no separators) "20200101T130000.000+01:00" "20200101T130000.000+01" "20200101T130000+01" "20200101T1300+01" // Extended, more common ISO 8601 format (with separators) "2020-01-01T12:00:00.000+00:00" // no millis "2020-01-01T12:00:00+00:00" // no seconds "2020-01-01T12:00+00:00" // offset -1 "2020-01-01T11:00:00.000-0100" "2020-01-01T11:00:00-0100" // offset +1 only offset hour (offset minute is optional in ISO 8601) "2020-01-01T13:00:00.000+01" "2020-01-01T13:00+01" // no T but space as separator between date and time // (allowed in RFC 3339, which is a profile of ISO 8601) "2020-01-01 13:00:00.000+0100" "2020-01-01 13:00+01:00"
- Parameters:
date
- the dateTimeString to parse- Returns:
- the parsed date as
Instant
-
parseFromISO8601FormatUTC
Parses the given string formatted with UTC date time in ISO 8601 format to an Instant. The given date must be ending with Z, representing UTC in ISO 8601 e.g. "2020-01-01T12:00:00.000Z" Offset date times are not supported. For wider support of ISO 8601 formats, seeparseFromISO8601Format(String)
- Parameters:
date
- the dateTimeString to parse- Returns:
- the parsed date as
Instant
-
parseISO8601
ISO 8601 formats usually carry are time zone offset. This method parses the given string to aZonedDateTime
, which is capable of carrying a time zone offset.Instant
does not carry a time zone offset, but is always a moment in time in UTC (ending with Z). ZonedDateTime can easily be converted to an Instant by callingChronoZonedDateTime.toInstant()
.- Parameters:
dateTimeString
- the string to parse- Returns:
- the parsed ZonedDateTime
-
formatInISO8601Format
-
formatInISO8601Format
-
formatInSimpleFormat
-
formatInSimpleFormatUS
-