Package org.elasticsearch.common.time
Interface DateFormatter
-
- All Known Implementing Classes:
EpochSecondsDateFormatter,JodaDateFormatter
public interface DateFormatter
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default 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 formatterdefault java.lang.StringformatJoda(org.joda.time.DateTime dateTime)Return the given JodaDateTimeformatted with this format.default java.lang.StringformatMillis(long millis)Return the given millis-since-epoch formatted with this format.static DateFormatterforPattern(java.lang.String input)java.util.Localelocale()Returns the configured locale of the date formatterjava.time.temporal.TemporalAccessorparse(java.lang.String input)Try to parse input to a java time TemporalAccessordefault org.joda.time.DateTimeparseJoda(java.lang.String input)Parse the given input into a JodaDateTime.default longparseMillis(java.lang.String input)Parse the given input into millis-since-epoch.java.lang.Stringpattern()A name based format for this formatter.DateMathParsertoDateMathParser()Return aDateMathParserbuilt from 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 zonejava.time.ZoneIdzone()Returns the configured time zone of the date formatter
-
-
-
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
-
parseMillis
default long parseMillis(java.lang.String input)
Parse the given input into millis-since-epoch.
-
parseJoda
default org.joda.time.DateTime parseJoda(java.lang.String input)
Parse the given input into a JodaDateTime.
-
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
-
formatMillis
default java.lang.String formatMillis(long millis)
Return the given millis-since-epoch formatted with this format.
-
formatJoda
default java.lang.String formatJoda(org.joda.time.DateTime dateTime)
Return the given JodaDateTimeformatted with this format.
-
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
-
locale
java.util.Locale locale()
Returns the configured locale of the date formatter- Returns:
- The locale of this formatter
-
zone
java.time.ZoneId zone()
Returns the configured time zone of the date formatter- Returns:
- The time zone of this formatter
-
toDateMathParser
DateMathParser toDateMathParser()
Return aDateMathParserbuilt from this formatter.
-
forPattern
static DateFormatter forPattern(java.lang.String input)
-
-