Java Date Time - LocalDateTime adjustInto(Temporal temporal) example








LocalDateTime adjustInto(Temporal temporal) adjusts the specified temporal object to have the same date and time as this object.

Syntax

adjustInto has the following syntax.

public Temporal adjustInto(Temporal temporal)

Example

The following example shows how to use adjustInto.

import java.time.LocalDateTime;
import java.time.temporal.Temporal;
/*from   w  w  w .  j  a  va  2 s.c  om*/
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);
    LocalDateTime b = LocalDateTime.now();
    
    Temporal t = a.adjustInto(b);
    
    System.out.println(t);
  }
}

The code above generates the following result.