Java Date Time - ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) example








ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) creates ZonedDateTime from the local date-time and offset.

Syntax

ofInstant has the following syntax.

public static ZonedDateTime ofInstant(LocalDateTime localDateTime,    
                                      ZoneOffset offset,    
                                      ZoneId zone)

Example

The following example shows how to use ofInstant.

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
/*  w  w w.j ava  2 s. c o  m*/
public class Main {
  public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.ofInstant(LocalDateTime.now(),ZoneOffset.UTC,ZoneId.systemDefault());
    
    System.out.println(z);

  }
}

The code above generates the following result.