Java LocalDateTime create from LocalDate and LocalTime

Description

Java LocalDateTime create from LocalDate and LocalTime

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

public class Main {
  public static void main(String[] args) {
    // Get the current local date time
    LocalDateTime ldt1 = LocalDateTime.now();

    // A local date time 2020-05-10T16:14:32
    LocalDateTime ldt2 = LocalDateTime.of(2020, Month.MAY, 10, 16, 14, 32);

    // Construct a local date time from a local date and a local time
    LocalDate ld1 = LocalDate.of(2020, 5, 10);
    LocalTime lt1 = LocalTime.of(16, 18, 41);
    LocalDateTime ldt3 = LocalDateTime.of(ld1, lt1); // 2020-05-10T16:18:41
    System.out.println(lt1);/*from  w  w  w . j a va 2s.  c o  m*/
    System.out.println(ldt1);
    System.out.println(ldt2);
    System.out.println(ldt3);
  }
}



PreviousNext

Related