What Is Instants in Java?

The Instant class in the Java date time API ( java. time. Instant ) represents a specific moment on the time line. The instant is defined as an offset since the origin (called an epoch).

What is an instant object?

public final class Instant extends Object implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable. An instantaneous point on the time-line. This class models a single instantaneous point on the time-line. This might be used to record event time-stamps in the application.

How do you create an instant in java?

Java Instant Example: minus()
  1. import java.time.*;
  2. public class InstantExample3 {
  3. public static void main(String[] args) {
  4. Instant instant = Instant.parse("2017-02-03T11:25:30.00Z");
  5. instant = instant.minus(Duration.ofDays(125));
  6. System.out.println(instant);
  7. }
  8. }
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.