ZonedDateTime toOffsetDateTime() example

Description

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 w  w . j  a va 2  s.c  o  m
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.





















Home »
  Java Date Time »
    java.time Reference »




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