Java Date Time - ZoneOffset adjustInto(Temporal temporal) example








ZoneOffset adjustInto(Temporal temporal) adjusts the specified temporal object to have the same offset 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.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
/*ww w .  j a v  a2 s. com*/
public class Main {
  public static void main(String[] args) {
    ZoneOffset z = ZoneOffset.UTC;
    Temporal t = z.adjustInto(ZonedDateTime.now());
    System.out.println(t);
  }
}

The code above generates the following result.