ZonedDateTime of(LocalDateTime localDateTime, ZoneId zone) example

Description

ZonedDateTime of(LocalDateTime localDateTime, ZoneId zone) creates an instance of ZonedDateTime from a local date-time.

Syntax

of has the following syntax.


public static ZonedDateTime of(LocalDateTime localDateTime,   ZoneId zone)

Example

The following example shows how to use of.


import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
//from  w ww .  ja va  2  s.c  o m
public class Main {
  public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.of(LocalDateTime.now(),ZoneId.systemDefault());
    
    System.out.println(z);
    
    LocalDateTime timePoint = LocalDateTime.now();
    ZoneId id = ZoneId.of("Europe/Paris");
    ZonedDateTime zoned = ZonedDateTime.of(timePoint, id);

    System.out.println(zoned);    

  }
}

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