OffsetDateTime ofInstant(Instant instant, ZoneId zone) example

Description

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;
//from w w  w. ja 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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset