ZoneOffset ofHoursMinutesSeconds(int, int, int) method in Java with Examples
The ofHoursMinutesSeconds(int, int, int) method of ZoneOffset Class in java.time package is used to obtain an instance of ZoneOffset using the offset in hours, minutes and seconds passed as the parameter. This method takes the hours, minutes and seconds as parameter in the form of int and converts it into the ZoneOffset.
public static ZoneOffset ofHoursMinutesSeconds(int hours, int minutes, int seconds)
Parameters: This method accepts 3 parameters:
- hours: which is int hours to be converted into an ZoneOffset instance. Its range is +18 to -18
- minutes: which is int minutes to be converted into an ZoneOffset instance. Its range is -59 to +59
- seconds: which is int seconds to be converted into an ZoneOffset instance. Its range is -59 to +59
Return Value: This method returns a ZoneOffset instance parsed from the specified hours, minutes and seconds.
Exception: This method throws DateTimeException if the hours, minutes and seconds is invalid.
Below examples illustrate the ZoneOffset.ofHoursMinutesSeconds() method:
Example 2: To demonstrate DateTimeException
java.time.DateTimeException: Zone offset hours not in valid range: value 20 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.