Class ConfigurableDateFormatter
- java.lang.Object
-
- com.flowable.platform.common.util.ConfigurableDateFormatter
-
public class ConfigurableDateFormatter extends Object
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
Constructors Constructor Description ConfigurableDateFormatter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
formatInISO8601Format(Instant instant)
static String
formatInISO8601Format(Date date)
static String
formatInSimpleFormat(Date date)
static String
formatInSimpleFormatUS(Date date)
static DateTimeFormatter
getISO8601Formatter()
static DateTimeFormatter
getSimpleFormatter()
static DateTimeFormatter
getSimpleFormatterUS()
ZoneId
getTimeZone()
static Instant
parseFromISO8601Format(String date)
Capable of parsing the given date string in different representations of valid ISO 8601 formatted strings.static Instant
parseFromISO8601FormatUTC(String date)
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)
-
-
-
Method Detail
-
setSimpleFormat
public static void setSimpleFormat(String simpleFormat)
-
setSimpleFormatUS
public static void setSimpleFormatUS(String simpleFormatUS)
-
setTimeZone
public static void setTimeZone(ZoneId timeZone)
-
setTimeZone
public static void setTimeZone(String timeZone)
-
getTimeZone
public ZoneId getTimeZone()
-
getISO8601Formatter
public static DateTimeFormatter getISO8601Formatter()
-
getSimpleFormatter
public static DateTimeFormatter getSimpleFormatter()
-
getSimpleFormatterUS
public static DateTimeFormatter getSimpleFormatterUS()
-
parseFromISO8601Format
public static Instant parseFromISO8601Format(String date)
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
public static Instant parseFromISO8601FormatUTC(String date)
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
protected static ZonedDateTime parseISO8601(String dateTimeString)
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
-
-