The from() method of OffsetTime class in Java obtains an instance of OffsetTime from a temporal object which is passed in the parameter of the method.
Syntax:
public static OffsetTime from(TemporalAccessor temporal)
Parameter: This method accepts a single mandatory parameter temporal which specifies the temporal object to be converted and it is not null.
Return Value: It returns the offset time and not null.
Below programs illustrate the from() method:
Program 1 :
// Java program to demonstrate the from() method import java.time.OffsetTime; import java.time.ZonedDateTime; public class GFG { public static void main(String[] args) { // Function called to get current time OffsetTime time = OffsetTime.from(ZonedDateTime.now()); // Prints the current time System.out.println("Current-time: " + time); } } |
Current-time: 13:07:59.941Z
Program 2 :
// Java program to demonstrate the from() method import java.time.OffsetTime; import java.time.ZonedDateTime; public class GFG { public static void main(String[] args) { // Function called to get current time OffsetTime time = OffsetTime.from(ZonedDateTime.now()); // Prints the current time System.out.println("Current-time: " + time); } } |
Current-time: 13:08:03.087Z
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.
Recommended Posts:
- OffsetTime getMinute() method in Java with examples
- OffsetTime getNano() method in Java with examples
- OffsetTime getHour() method in Java with examples
- OffsetTime get() method in Java with examples
- OffsetTime adjustInto() method in Java with examples
- OffsetTime isEqual() method in Java with examples
- OffsetTime isAfter() method in Java with examples
- OffsetTime isBefore() method in Java with examples
- OffsetTime format() method in Java with examples
- OffsetTime compareTo() method in Java with examples
- OffsetTime equals() method in Java with examples
- OffsetTime getOffset() method in Java with examples
- OffsetTime minus() method in Java with examples
- OffsetTime now() method in Java with examples
- OffsetTime atDate() method in Java with examples
- OffsetTime getLong() method in Java with examples
- OffsetTime plus() method in Java with examples
- OffsetTime parse() method in Java with examples
- OffsetTime ofInstant() method in Java with examples
- OffsetTime plusHours() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.

