OffsetTime of() method in Java with Examples
The of(int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetTime class in Java is used to create an instance of OffsetTime from the passed values of hour, minute, second and nanosecond. In this method, we pass the value of hour, minute, second and nanosecond in integer form and it returns time on basis of these values as OffsetTime.
public static OffsetTime of(int hour, int minute, int second, int nanosecond, ZoneOffset offset)
Parameters: The method accepts five parameters:
- hour – It represents the hour of the day. It varies from 0 to 23.
- minute – It represents the minute of the hour. It varies from 0 to 59.
- second – It represents the second of the minute. It varies from 0 to 59.
- nanosecond – It represents the nano of the second. It varies from 0 to 999999999.
- offset – It represents the zone offset. It should not be null.
Return value: This method always returns the OffsetTime.
Exception: This method throws DateTimeException if any parameter value is out of the range.
Below programs illustrate the of() method of OffsetTime class in Java:
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.