Java Date Time - OffsetDateTime ofInstant(Instant instant, ZoneId zone) example








OffsetDateTime ofInstant(Instant instant, ZoneId zone) creates an instance of OffsetDateTime from an Instant and zone ID.

Syntax

ofInstant has the following syntax.

public static OffsetDateTime ofInstant(Instant instant,    ZoneId zone)

Example

The following example shows how to use ofInstant.

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
/* w w  w.  j  a v  a  2  s .co  m*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.ofInstant(Instant.now(),ZoneId.systemDefault());
    
    System.out.println(o);
  }
}

The code above generates the following result.