java.time.OffsetTime.from() Method Example
Description
The java.time.OffsetTime.from(TemporalAccessor temporal) method obtains an instance of OffsetTime from a temporal object.
Declaration
Following is the declaration for java.time.OffsetTime.from(TemporalAccessor temporal) method.
public static OffsetTime from(TemporalAccessor temporal)
Parameters
temporal − the temporal object to convert, not null.
Return Value
the offset time, not null.
Exceptions
DateTimeException − if unable to convert to a OffsetTime.
Example
The following example shows the usage of java.time.OffsetTime.from(TemporalAccessor temporal) method.
package com.tutorialspoint;
import java.time.OffsetTime;
import java.time.ZonedDateTime;
public class OffsetTimeDemo {
public static void main(String[] args) {
OffsetTime date = OffsetTime.from(ZonedDateTime.now());
System.out.println(date);
}
}
Let us compile and run the above program, this will produce the following result −
10:39:57.257+05:30
Advertisements