ZoneOffset of(String) method in Java with Examples Last Updated : 11 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The of(String) method of ZoneOffset Class in java.time package is used to obtain an instance of ZoneOffset using the offsetId passed as the parameter. This method takes the offsetId as parameter in the form of String and converts it into the ZoneOffset. The ID of the returned offset will be normalized to one of the formats described by getId(). The list of String offsetId accepted by this method are as follows: Z - for UTC +h +hh +hh:mm -hh:mm +hhmm -hhmm +hh:mm:ss -hh:mm:ss +hhmmss -hhmmss Note: ± means either the plus or minus symbol. And the maximum supported range is from +18:00 to -18:00 inclusive. Syntax: public static ZoneOffset of(String offsetId) Parameters: This method accepts a parameter offsetId which is String to be parsed into an ZoneOffset instance. Return Value: This method returns a ZoneOffset instance parsed from the specified offsetId. Exception: This method throws DateTimeException if the offset ID is invalid. Below examples illustrate the ZoneOffset.of() method: Example 1: Java // Java code to illustrate of() method import java.time.*; public class GFG { public static void main(String[] args) { // Get the offset ID String offsetId = "Z"; // ZoneOffset using of() method ZoneOffset zoneOffset = ZoneOffset.of(offsetId); System.out.println(zoneOffset); } } Output: Z Example 2: To demonstrate DateTimeException Java // Java code to illustrate of() method import java.time.*; public class GFG { public static void main(String[] args) { // Get the invalid offset ID String offsetId = "10:10"; try { // ZoneOffset using of() method ZoneOffset zoneOffset = ZoneOffset.of(offsetId); } catch (Exception e) { System.out.println(e); } } } Output: java.time.DateTimeException: Invalid ID for ZoneOffset, non numeric characters found: 10:10 Reference: Oracle Doc Comment More infoAdvertise with us Next Article Field toString() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-time package Java-ZoneOffset Practice Tags : Java Similar Reads ZoneOffset toString() method in Java with Examples The toString() method of ZoneOffset Class in java.time package is used to obtain String representation of this instance of ZoneOffset. This method does not takes any parameter and returns an String value. which is the String representation. Syntax: public static String toString() Parameters: This me 1 min read Year toString() method in Java with Examples The toString() method of Year class in Java is used to return the string representation of this Year object. Syntax: public String toString() Parameter: This method does not accepts any parameter. Return Value: It returns the string representation of this Year object. Below programs illustrate the t 1 min read Byte toString() method in Java with examples The toString() method of Byte class is a built in method in Java which is used to return a String value. public String toString() Syntax: ByteObject.toString() Return Value: It returns a String object, the value of which is equal to the value of the ByteObject. Below is the implementation of toStrin 2 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Field toString() method in Java with Examples The toString() method of java.lang.reflect.Field is used to get a string describing this Field. The format of the returned string is the access modifiers for the field, if any, followed by the field type, followed by a space, followed by the fully-qualified name of the class declaring the field, fol 3 min read Optional toString() method in Java with examples The toString() method of java.util.Optional class in Java is used to get the string representation of this Optional instance. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this Optional instance. Below program 1 min read Like