OffsetTime from() method in Java with examples
Last Updated :
13 Dec, 2018
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 :
import java.time.OffsetTime;
import java.time.ZonedDateTime;
public class GFG {
public static void main(String[] args)
{
OffsetTime time
= OffsetTime.from(ZonedDateTime.now());
System.out.println( "Current-time: "
+ time);
}
}
|
Output:
Current-time: 13:07:59.941Z
Program 2 :
import java.time.OffsetTime;
import java.time.ZonedDateTime;
public class GFG {
public static void main(String[] args)
{
OffsetTime time
= OffsetTime.from(ZonedDateTime.now());
System.out.println( "Current-time: "
+ time);
}
}
|
Output:
Current-time: 13:08:03.087Z
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#from-java.time.temporal.TemporalAccessor-
Share your thoughts in the comments
Please Login to comment...