Java Date Time - OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset) example








OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset) creates an instance of OffsetDateTime from a date-time and offset.

Syntax

of has the following syntax.

public static OffsetDateTime of(LocalDateTime dateTime,   ZoneOffset offset)

Example

The following example shows how to use of.

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
/* w  w  w  . j  av  a2s.c om*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.UTC);
    
    System.out.println(o);
  }
}

The code above generates the following result.