Java Date Time - ZonedDateTime toOffsetDateTime() example








ZonedDateTime toOffsetDateTime() converts this date-time to an OffsetDateTime.

Syntax

toOffsetDateTime has the following syntax.

public OffsetDateTime toOffsetDateTime()

Example

The following example shows how to use toOffsetDateTime.

import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
// w  ww .  ja v  a 2 s  . c  om
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    OffsetDateTime o =  dateTime.toOffsetDateTime();
    System.out.println(o);
  } 
}

The code above generates the following result.