OffsetTime ofInstant() method in Java with examples

The ofInstant() method of a OffsetTime class is used to obtain an instance of OffsetTime from an Instant and zone ID passed as parameters.In this method First, the offset from UTC/Greenwich is obtained using the zone ID and instant. Then, the local time has calculated from the instant and offset.


public static OffsetTime 
       ofInstant(Instant instant, ZoneId zone)

Parameters: This method accepts two parameters:

  • instant: It is the instant from which the OffsetTime object is to be created. It should not be null.
  • zone: It is the zone of the specified time. It should not be null.

Return value: This method returns the created OffsetTime object created from the passed instant.

Below program illustrate the ofInstant() method:





// Java program to demonstrate
// OffsetTime.ofInstant() method
import java.time.OffsetTime;
import java.time.Instant;
import java.time.ZoneId;
public class GFG {
    public static void main(String[] args)
        // Creates an instance
        OffsetTime time = OffsetTime.ofInstant(, 
        System.out.println("Offset time: " + time);



Offset time: 03:17:43.019Z


Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.