We have launched a free Basic Kubernetes Course. Click here to enrol now! Kubernetes is a container orchestration platform used by enterprises worldwide and Kubernetes developers are in high demand!
represents a point in time independent of Chronology or TimeZone.
- Creating Instant
- Comparing Two Instants
- Get Sub-Fields of Instant
- Perform Arithmentic Operations On Instant like Addition, Subtraction and Repeated Addition
- Convert Instant To Other Representations Like DateTime, MutableDateTime,JDK Date and String
can be created in the following ways:
- Using null argument to create Instant for current DateTime
- Using Instant.now()to create Instant for current DateTime
- Using millis
- Using another Instant
- Parsing from String representation
Comparing Two Instants
There are two ways to compare Instants:
- Using Instant.compareTo() method.
The return type is an integer whose values follow the contract mentioned in Comparable interface
- Using convenience methods line Instant.isBefore(),Instant.isAfter() and Instant.isEqual()
The return type in this case is boolean.
The first approach is typically used in comparator logic for sorting.
Get Sub-Fields of Instant
This example shows how to extract sub fields of an Instant.
In this example, only year, month and day have been shown. However any sub-field can be derived in a similar manner
Perform Arithmentic Operations On Instant like Addition, Subtraction and Repeated Addition
The following types of arithmetic operations are supported in Joda-Time:
- Repeated Addition
Convert Instant To Other Representations Like DateTime, MutableDateTime,JDK Date and String
To start, click on the next arrow. If you find anything missing in the tutorials then please drop in your comments.