The adjustInto() method of LocalTime class is used to adjusts the specified temporal object to have the same time as this LocalTime Object. Syntax:
public Temporal adjustInto(Temporal temporal)
Parameters: This method accepts a single parameter temporal which is the target object to be adjusted, and not specifically null. Return value: This method returns the adjusted temporal object. Exception: The function throws two exceptions as described below:
- DateTimeException– if unable to make the adjustment
- ArithmeticException – if numeric overflow occurs
Below programs illustrate the adjustInto() method: Program 1:Â
Java
// Java program to demonstrate// LocalTime.adjustInto() methodÂ
import java.time.*;Â
public class GFG {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â
        // create a LocalTime Object        LocalTime local            = LocalTime.parse("09:32:42");Â
        // create Zone Time        ZonedDateTime zonetime = ZonedDateTime.now();Â
        // print Zone Time        System.out.println("ZonedDateTime"                           + " before adjustInto():"                           + zonetime.toString());Â
        // apply adjustInto()        zonetime = (ZonedDateTime)local                       .adjustInto(zonetime);Â
        // print Zone Time        System.out.println("ZonedDateTime"                           + " after adjustInto():"                           + zonetime.toString());    }} |
ZonedDateTime before adjustInto():2018-12-03T06:30:31.142Z[Etc/UTC] ZonedDateTime after adjustInto():2018-12-03T09:32:42Z[Etc/UTC]
Program 2:Â
Java
// Java program to demonstrate// LocalTime.adjustInto() methodÂ
import java.time.*;import java.time.temporal.Temporal;Â
public class GFG {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â
        // create a LocalTime Object        LocalTime local = LocalTime.parse("19:52:43");Â
        // create a Temporal object        // which is equal to OffsetDateTime object        OffsetDateTime passTemporal            = OffsetDateTime.now();Â
        // print passed Value        System.out.println("Before adjustInto() OffsetDateTime: "                           + passTemporal);Â
        // apply adjustInto method        // to adjust OffsetDateTime Temporal        Temporal returnTemporal            = local.adjustInto(passTemporal);Â
        // print results        System.out.println("After adjustInto() OffsetDateTime: "                           + (OffsetDateTime)returnTemporal);    }} |
Before adjustInto() OffsetDateTime: 2018-12-03T06:30:33.927Z After adjustInto() OffsetDateTime: 2018-12-03T19:52:43Z

… [Trackback]
[…] Find More Info here to that Topic: geeksforgeeks.org/localtime-adjustinto-method-in-java-with-examples/ […]