java.time.LocalDateTime.of() Method Example



Description

The java.time.LocalDateTime.of(LocalDate date, LocalTime time) method obtains an instance of LocalDateTime from a date and time.

Declaration

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

public static LocalDateTime of(LocalDate date, LocalTime time)

Parameters

  • date − the local date, not null

  • time − the local time, not null

Return Value

the local date-time, not null.

Example

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

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

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

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

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

2017-02-03T12:30:30
Advertisements