ZoneOffset adjustInto(Temporal) method in Java with Examples
The adjustInto(Temporal) method of ZoneOffset Class in java.time package is used to obtain an adjusted Temporal instance with this instance of ZoneOffset adjusted into it. This method takes the Temporal instance as parameter and returns an Temporal instance, which is the adjusted instance.
Syntax:
public Temporal adjustInto(Temporal temporalInstance)
Parameters: This method accepts accepts a parameter temporalInstance which is the Temporal instance to be adjusted.
Return Value: This method returns a Temporal instance which is the adjusted value of this Temporal instance.
Exceptions: This method throws following exceptions:
- DateTimeException: if unable to make the adjustment
- ArithmeticException: if numeric overflow occurs.
Below examples illustrate the ZoneOffset.adjustInto() method:
Example 1:
// Java code to illustrate adjustInto() method import java.time.temporal.*; import java.time.*; public class GFG { public static void main(String[] args) { // Get the Temporal instance ZonedDateTime temporalInstance = ZonedDateTime.now(); System.out.println("Original Temporal instance: " + temporalInstance); // Get the ZoneOffset ZoneOffset zoneOffset = ZoneOffset.ofHours(5); // Using adjustInto() method ZonedDateTime adjustedTemporal = (ZonedDateTime)zoneOffset .adjustInto(temporalInstance); System.out.println("Adjusted Temporal instance: " + adjustedTemporal); } } |
Original Temporal instance: 2018-12-11T09:44:14.373Z[Etc/UTC] Adjusted Temporal instance: 2018-12-11T09:44:14.373Z[Etc/UTC]
Example 2:
// Java code to illustrate adjustInto() method import java.time.temporal.*; import java.time.*; public class GFG { public static void main(String[] args) { // Get the Temporal instance OffsetDateTime temporalInstance = OffsetDateTime.now(); System.out.println("Original Temporal instance: " + temporalInstance); // Get the ZoneOffset ZoneOffset zoneOffset = ZoneOffset.ofHours(5); // Using adjustInto() method Temporal adjustedTemporal = zoneOffset .adjustInto(temporalInstance); System.out.println("Adjusted Temporal instance: " + adjustedTemporal); } } |
Original Temporal instance: 2018-12-11T09:44:16.893Z Adjusted Temporal instance: 2018-12-11T09:44:16.893+05:00
Reference: Oracle Doc
Recommended Posts:
- ZoneOffset compareTo(ZoneOffset) method in Java with Examples
- ZoneOffset normalized() method in Java with Examples
- ZoneOffset hashCode() method in Java with Examples
- ZoneOffset toString() method in Java with Examples
- ZoneOffset getDisplayName() method in Java with Examples
- ZoneOffset getAvailableZoneIds() method in Java with Examples
- ZoneOffset getRules() method in Java with Examples
- ZoneOffset get(TemporalField) method in Java with Examples
- ZoneOffset getId() method in Java with Examples
- ZoneOffset getTotalSeconds() method in Java with Examples
- ZoneOffset ofHours(int) method in Java with Examples
- ZoneOffset ofHoursMinutesSeconds(int, int, int) method in Java with Examples
- ZoneOffset of(String) method in Java with Examples
- ZoneOffset from(TemporalAccessor) method in Java with Examples
- ZoneOffset ofHoursMinutes(int, int) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



