ZoneId from() method in Java with Examples
The from() method of the ZoneId class used to get instance of ZoneId from TemporalAccessor object passed as parameter.This method obtains a zone based on the TemporalAccessor which represents an arbitrary set of date and time information, which this method converts to an instance of ZoneId.
Syntax:
public static ZoneId from(TemporalAccessor temporal)
Parameters: This method accepts a single parameter temporal which represents the temporal object to convert, It can’t be null.
Return value: This method returns the zone ID, which can not be null.
Exception: This method throws the DateTimeException if this method is unable to convert temporal to a ZoneId.
Below programs illustrate the from() method:
Program 1:
// Java program to demonstrate // ZoneId.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create TemporalAccessor object ZonedDateTime zoneddatetime = ZonedDateTime.parse("2018-10-25T23:12:31.123+02:00[Europe/Paris]"); // get ZoneId from this TemporalAccessor ZoneId response = ZoneId.from(zoneddatetime); // print result System.out.println("Zone Id got from " + "TemporalAccessor object \n" + zoneddatetime + "\nis " + response); } } |
Zone Id got from TemporalAccessor object 2018-10-25T23:12:31.123+02:00[Europe/Paris] is Europe/Paris
Program 2:
// Java program to demonstrate // ZoneId.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create TemporalAccessor object ZonedDateTime zoneddatetime = ZonedDateTime.now(); // get ZoneId from this TemporalAccessor ZoneId response = ZoneId.from(zoneddatetime); // print result System.out.println("Zone Id got from " + "TemporalAccessor object \n" + zoneddatetime + "\nis " + response); } } |
Zone Id got from TemporalAccessor object 2018-12-10T18:20:03.637Z[Etc/UTC] is Etc/UTC
References:
https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#from(java.lang.Object)
Recommended Posts:
- ZoneId getId() method in Java with Examples
- ZoneId equals() method in Java with Examples
- ZoneId getRules() method in Java with Examples
- ZoneId normalized() method in Java with Examples
- ZoneId hashCode() method in Java with Examples
- ZoneId getDisplayName() method in Java with Examples
- ZoneId ofOffset() method in Java with Examples
- ZoneId systemDefault() method in Java with Examples
- ZoneId getAvailableZoneIds() method in Java with Examples
- ZoneId toString() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.builtcount() 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.
Improved By : Akanksha_Rai



