Java Date Time - Instant from(TemporalAccessor temporal) example








Instant from(TemporalAccessor temporal) gets an instance of Instant from a temporal object.

This obtains an instant based on the specified temporal.

The conversion extracts the INSTANT_SECONDS and NANO_OF_SECOND fields.

Syntax

from has the following syntax.

public static Instant from(TemporalAccessor temporal)

Example

The following example shows how to use from.

import java.time.Instant;
import java.time.ZonedDateTime;
/*from w w  w  .j  av a  2  s  .  co m*/
public class Main {
  public static void main(String[] args) {
    Instant instant = Instant.from(ZonedDateTime.now());
    System.out.println(instant.getEpochSecond());
    
  }
}

The code above generates the following result.