Package co.elastic.clients.util
Class DateTime
java.lang.Object
co.elastic.clients.util.DateTime
- All Implemented Interfaces:
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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Create a new date-time or a date-math expression from a string.static DateTime
of
(String text, DateTimeFormatter parser) Create a new date-time from a string and parser.static DateTime
Create a new date-time from aTemporal
object.static DateTime
of
(Temporal instant, 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, DateTimeFormatter format) Create a new date-time from Epoch milliseconds.void
serialize
(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper) long
Get the milliseconds since the Epoch for represented by this object.long
toEpochMilli
(DateTimeFormatter format) Get the milliseconds since the Epoch for represented by this object.Converts this object to anInstant
.toInstant
(DateTimeFormatter parser) Converts this object to anInstant
, using a given format.toString()
Converts this object to anZonedDateTime
.toZonedDateTime
(DateTimeFormatter parser) Converts this object to anZonedDateTime
, using a given format.
-
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
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
Get the string that was used to create this date-time, ornull
if it was created with a number of milliseconds. -
toInstant
Converts this object to anInstant
.- Throws:
DateTimeParseException
- if this object was created from a string which can not be parsed
-
toInstant
Converts this object to anInstant
, using a given format.- Parameters:
parser
- the parser to use if this object was created from a string- Throws:
DateTimeParseException
- if this object was created from a string which can not be parsed
-
toZonedDateTime
Converts this object to anZonedDateTime
.- Throws:
DateTimeParseException
- if this object was created from a string which can not be parsed
-
toZonedDateTime
Converts this object to anZonedDateTime
, using a given format.- Parameters:
parser
- the parser to use if this object was created from a string- Throws:
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:
DateTimeParseException
- if this object was created from a string which can not be parsed
-
toEpochMilli
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:
DateTimeParseException
- if this object was created from a string which can not be parsed
-
serialize
- Specified by:
serialize
in interfaceJsonpSerializable
-
equals
-
hashCode
public int hashCode() -
toString
-