Package org.elasticsearch.common.time
Interface DateFormatter
-
- All Known Implementing Classes:
DateFormatter.MergedDateFormatter,EpochSecondsDateFormatter
public interface DateFormatter
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDateFormatter.MergedDateFormatter
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Stringformat(java.time.temporal.TemporalAccessor accessor)Print the supplied java time accessor in a string based representation according to this formatterjava.util.LocalegetLocale()Returns the configured locale of the date formatterjava.time.ZoneIdgetZone()Returns the configured time zone of the date formatterstatic DateFormattermerge(DateFormatter... formatters)Merge several date formatters into a single one.java.time.temporal.TemporalAccessorparse(java.lang.String input)Try to parse input to a java time TemporalAccessorDateFormatterparseDefaulting(java.util.Map<java.time.temporal.TemporalField,java.lang.Long> fields)Configure a formatter using default fields for a TemporalAccessor that should be used in case the supplied date is not having all of those fieldsjava.lang.Stringpattern()A name based format for this formatter.DateFormatterwithLocale(java.util.Locale locale)Create a copy of this formatter that is configured to parse dates in the specified localeDateFormatterwithZone(java.time.ZoneId zoneId)Create a copy of this formatter that is configured to parse dates in the specified time zone
-
-
-
Method Detail
-
parse
java.time.temporal.TemporalAccessor parse(java.lang.String input)
Try to parse input to a java time TemporalAccessor- Parameters:
input- An arbitrary string resembling the string representation of a date or time- Returns:
- The java time object containing the parsed input
- Throws:
java.time.format.DateTimeParseException- If parsing fails, this exception will be thrown. Note that it can contained suppressed exceptions when several formatters failed parse this value
-
withZone
DateFormatter withZone(java.time.ZoneId zoneId)
Create a copy of this formatter that is configured to parse dates in the specified time zone- Parameters:
zoneId- The time zone to act on- Returns:
- A copy of the date formatter this has been called on
-
withLocale
DateFormatter withLocale(java.util.Locale locale)
Create a copy of this formatter that is configured to parse dates in the specified locale- Parameters:
locale- The local to use for the new formatter- Returns:
- A copy of the date formatter this has been called on
-
format
java.lang.String format(java.time.temporal.TemporalAccessor accessor)
Print the supplied java time accessor in a string based representation according to this formatter- Parameters:
accessor- The temporal accessor used to format- Returns:
- The string result for the formatting
-
pattern
java.lang.String pattern()
A name based format for this formatter. Can be one of the registered formatters likeepoch_millisor a configured format likeHH:mm:ss- Returns:
- The name of this formatter
-
getLocale
java.util.Locale getLocale()
Returns the configured locale of the date formatter- Returns:
- The locale of this formatter
-
getZone
java.time.ZoneId getZone()
Returns the configured time zone of the date formatter- Returns:
- The time zone of this formatter
-
parseDefaulting
DateFormatter parseDefaulting(java.util.Map<java.time.temporal.TemporalField,java.lang.Long> fields)
Configure a formatter using default fields for a TemporalAccessor that should be used in case the supplied date is not having all of those fields- Parameters:
fields- AMap<TemporalField, Long>of fields to be used as fallbacks- Returns:
- A new date formatter instance, that will use those fields during parsing
-
merge
static DateFormatter merge(DateFormatter... formatters)
Merge several date formatters into a single one. Useful if you need to have several formatters with different formats act as one, for example when you specify a format likedate_hour||epoch_millis- Parameters:
formatters- The list of date formatters to be merged together- Returns:
- The new date formtter containing the specified date formatters
-
-