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 boolean
equals(java.lang.Object o)
java.lang.String
getString()
Get the string that was used to create this date-time, ornull
if it was created with a number of milliseconds.int
hashCode()
static DateTime
of(java.lang.String text)
Create a new date-time or a date-math expression from a string.static DateTime
of(java.lang.String text, java.time.format.DateTimeFormatter parser)
Create a new date-time from a string and parser.static DateTime
of(java.time.temporal.Temporal instant)
Create a new date-time from aTemporal
object.static DateTime
of(java.time.temporal.Temporal instant, java.time.format.DateTimeFormatter format)
Create a new date-time from aTemporal
object.static DateTime
ofEpochMilli(long epochMilli)
Create a new date-time from Epoch milliseconds.static DateTime
ofEpochMilli(long epochMilli, java.time.format.DateTimeFormatter format)
Create a new date-time from Epoch milliseconds.void
serialize(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper)
long
toEpochMilli()
Get the milliseconds since the Epoch for represented by this object.long
toEpochMilli(java.time.format.DateTimeFormatter format)
Get the milliseconds since the Epoch for represented by this object.java.time.Instant
toInstant()
Converts this object to anInstant
.java.time.Instant
toInstant(java.time.format.DateTimeFormatter parser)
Converts this object to anInstant
, using a given format.java.lang.String
toString()
java.time.ZonedDateTime
toZonedDateTime()
Converts this object to anZonedDateTime
.java.time.ZonedDateTime
toZonedDateTime(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 anInstant
will 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 aTemporal
object. 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 aTemporal
object. 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, ornull
if 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:
serialize
in interfaceJsonpSerializable
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-