OffsetDateTime from(TemporalAccessor temporal) example

Description

OffsetDateTime from(TemporalAccessor temporal) creates an instance of OffsetDateTime from a temporal object.

Syntax

from has the following syntax.


public static OffsetDateTime from(TemporalAccessor temporal)

Example

The following example shows how to use from.


import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
//w  ww  .  j  a v  a  2s. c  o  m
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.from(ZonedDateTime.now());
    
    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