Java Date Time - LocalDateTime atOffset(ZoneOffset offset) example








LocalDateTime atOffset(ZoneOffset offset) combines this date-time with an offset to create an OffsetDateTime.

Syntax

atOffset has the following syntax.

public OffsetDateTime atOffset(ZoneOffset offset)

Example

The following example shows how to use atOffset.

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
//www  . j ava  2  s  .  c  om
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);

    OffsetDateTime b = a.atOffset(ZoneOffset.UTC);
    System.out.println(b);
  }
}

The code above generates the following result.