ZoneOffset get(TemporalField) method in Java with Examples
The get(TemporalField) method of ZoneOffset Class in java.time package is used to get the value of the specified TemporalField from this ZoneOffset instance. This method takes the TemporalField as the parameter and returns an integer value of this field.
public int get(TemporalField temporalField)
Parameters: This method accepts accepts a parameter temporalField which is required from this ZoneOffset instance.
Return Value: This method returns an integer value which is the field value of the temporalField passed as the parameter to this ZoneOffset instance.
Exceptions: This method throws:
- DateTimeException: if a value for the field cannot be obtained or the value is outside the range of valid values for the field
- UnsupportedTemporalTypeException: if the field is not supported or the range of values exceeds an int
- ArithmeticException: if numeric overflow occurs
Below examples illustrate the ZoneOffset.get() method:
ZoneOffset: +05:00 Second value: 18000
Example 2: To show DateTimeException
java.time.DateTimeException: Zone offset hours not in valid range: value 25 is not in the range -18 to 18
Reference: Oracle Doc
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.