OffsetDateTime ofInstant() method in Java with Examples
The ofInstant(Instant instant, ZoneId zone) method of the OffsetDateTime class in Java is used to create an instance of OffsetDateTime from the specified instant and zoneID. Since there is only one valid offset for each instant in UTC/Greenwich, it is simple to derive an offset from the latter.
public static OffsetDateTime ofInstant(Instant instant, ZoneId zone)
Parameters: This method accepts two parameters:
- instant – It is of Instant type and represents the instant at which offsetdatetime is created. It should not be null.
- zone – It is of ZoneId type and represents the zone for the time. It should not be null.
Return value: This method returns the OffsetDateTime created from the specified parameters.
Exception: This method throws DateTimeException if the result is beyond the supported range.
Below programs illustrate the ofInstant() method of OffsetDateTime 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.