Java LocalDateTime convert to LocalDate and LocalTime

Description

Java LocalDateTime convert to LocalDate and LocalTime

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

public class Main {
  public static void main(String[] args) {
    LocalDateTime ldt2 = LocalDateTime.now();
    System.out.println("ldt2: " + ldt2);

    // Derive the local date and time from the local date time
    LocalDate ld2 = LocalDate.from(ldt2);
    LocalTime lt2 = LocalTime.from(ldt2);
    System.out.println("ld2: " + ld2);
    System.out.println("lt2: " + lt2);

  }/*from  w ww.  j a  v a2  s.c  om*/
}



PreviousNext

Related