Package co.elastic.clients.util
Class DateTime
java.lang.Object
co.elastic.clients.util.DateTime
- All Implemented Interfaces:
JsonpSerializable
@JsonpDeserializable public class DateTime extends java.lang.Object implements JsonpSerializable
A date-time that can be represented either as a string or a number of milliseconds since the Epoch.
The string for can also be used to represent date-math expressions where applicable.
-
Field Summary
Fields Modifier and Type Field Description static JsonpDeserializer<DateTime>_DESERIALIZER -
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object o)java.lang.StringgetString()Get the string that was used to create this date-time, ornullif it was created with a number of milliseconds.inthashCode()static DateTimeof(java.lang.String text)Create a new date-time or a date-math expression from a string.static DateTimeof(java.lang.String text, java.time.format.DateTimeFormatter parser)Create a new date-time from a string and parser.static DateTimeof(java.time.temporal.Temporal instant)Create a new date-time from aTemporalobject.static DateTimeof(java.time.temporal.Temporal instant, java.time.format.DateTimeFormatter format)Create a new date-time from aTemporalobject.static DateTimeofEpochMilli(long epochMilli)Create a new date-time from Epoch milliseconds.static DateTimeofEpochMilli(long epochMilli, java.time.format.DateTimeFormatter format)Create a new date-time from Epoch milliseconds.voidserialize(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper)longtoEpochMilli()Get the milliseconds since the Epoch for represented by this object.longtoEpochMilli(java.time.format.DateTimeFormatter format)Get the milliseconds since the Epoch for represented by this object.java.time.InstanttoInstant()Converts this object to anInstant.java.time.InstanttoInstant(java.time.format.DateTimeFormatter parser)Converts this object to anInstant, using a given format.java.lang.StringtoString()java.time.ZonedDateTimetoZonedDateTime()Converts this object to anZonedDateTime.java.time.ZonedDateTimetoZonedDateTime(java.time.format.DateTimeFormatter parser)Converts this object to anZonedDateTime, using a given format.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Field Details
-
_DESERIALIZER
-
-
Method Details
-
ofEpochMilli
Create a new date-time from Epoch milliseconds. It will be serialized to JSON as a string.- Parameters:
epochMilli- the timestampformat- the format used to format the date-time as a JSON string
-
ofEpochMilli
Create a new date-time from Epoch milliseconds. It will be serialized to JSON as a number.- Parameters:
epochMilli- the timestamp
-
of
Create a new date-time or a date-math expression from a string. It will be serialized to JSON as is, conversion to anInstantwill use the default parsers.- Parameters:
text- the date-time as a string, or a date-math expression. If a date-math expression, the result will fail to be converted to another type.
-
of
Create a new date-time from a string and parser. It will be serialized to JSON as is.- Parameters:
text- the date-time as a stringparser- the parser used to convert the date-time to anInstant
-
of
Create a new date-time from aTemporalobject. It will be serialized to JSON as milliseconds since the Epoch.- Parameters:
instant- the date-time
-
of
public static DateTime of(java.time.temporal.Temporal instant, java.time.format.DateTimeFormatter format)Create a new date-time from aTemporalobject. It will be serialized to JSON as a string.- Parameters:
instant- the date-timeformat- the format used to convert to a JSON string
-
getString
@Nullable public java.lang.String getString()Get the string that was used to create this date-time, ornullif it was created with a number of milliseconds. -
toInstant
public java.time.Instant toInstant()Converts this object to anInstant.- Throws:
java.time.format.DateTimeParseException- if this object was created from a string which can not be parsed
-
toInstant
public java.time.Instant toInstant(java.time.format.DateTimeFormatter parser)Converts this object to anInstant, using a given format.- Parameters:
parser- the parser to use if this object was created from a string- Throws:
java.time.format.DateTimeParseException- if this object was created from a string which can not be parsed
-
toZonedDateTime
public java.time.ZonedDateTime toZonedDateTime()Converts this object to anZonedDateTime.- Throws:
java.time.format.DateTimeParseException- if this object was created from a string which can not be parsed
-
toZonedDateTime
public java.time.ZonedDateTime toZonedDateTime(java.time.format.DateTimeFormatter parser)Converts this object to anZonedDateTime, using a given format.- Parameters:
parser- the parser to use if this object was created from a string- Throws:
java.time.format.DateTimeParseException- if this object was created from a string which can not be parsed
-
toEpochMilli
public long toEpochMilli()Get the milliseconds since the Epoch for represented by this object. If it was created from a string, it is first converted usingtoInstant().- Throws:
java.time.format.DateTimeParseException- if this object was created from a string which can not be parsed
-
toEpochMilli
public long toEpochMilli(java.time.format.DateTimeFormatter format)Get the milliseconds since the Epoch for represented by this object. If it was created from a string, it is first converted usingtoInstant(DateTimeFormatter).- Parameters:
format- the parser to use if this object was created from a string- Throws:
java.time.format.DateTimeParseException- if this object was created from a string which can not be parsed
-
serialize
- Specified by:
serializein interfaceJsonpSerializable
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-