Java Date Time - OffsetDateTime toInstant() example








OffsetDateTime toInstant() converts this date-time to an Instant.

Syntax

toInstant has the following syntax.

public Instant toInstant()

Example

The following example shows how to use toInstant.

import java.time.Instant;
import java.time.OffsetDateTime;
/*from w  w  w .j av a 2s  .  com*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.MAX;
    Instant i = o.toInstant();
    System.out.println(i.getNano());
  }
}

The code above generates the following result.