java.time.ZonedDateTime.of() Method Example



Description

The java.time.ZonedDateTime.of(LocalDate date, LocalTime time, ZoneId zone) method obtains an instance of ZonedDateTime from a date, time and time-zone.

Declaration

Following is the declaration for java.time.ZonedDateTime.of(LocalDate date, LocalTime time, ZoneId zone) method.

public static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone)

Parameters

  • date − the local date, not null

  • time − the local time, not null

  • zone − the time-zone, not null

Return Value

the zoned date-time, not null.

Example

The following example shows the usage of java.time.ZonedDateTime.of(LocalDate date, LocalTime time, ZoneId zone) method.

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.LocalTime;
import java.time.ZoneId;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {

      LocalDate localDate = LocalDate.parse("2017-02-03");
      LocalTime localTime = LocalTime.parse("12:30:30");
      ZonedDateTime date = ZonedDateTime.of(localDate, localTime, ZoneId.systemDefault());
      System.out.println(date);  
   }
}

Let us compile and run the above program, this will produce the following result −

2017-02-03T12:30:30+05:30[Asia/Calcutta]
Advertisements