OffsetDateTime from() method in Java with examples Last Updated : 11 Jun, 2021 Comments Improve Suggest changes Like Article Like Report The from() method of OffsetDateTime class in Java obtains an instance of OffsetDateTime from a temporal object.Syntax : public static OffsetDateTime from(TemporalAccessor temporal) Parameter : This method accepts a single parameter temporal which specifies the temporal object to convert, not null.Return Value: It returns the local date, not null.Exceptions: The function throws a DateTimeException that is if it is unable to convert to a OffsetDateTime.Below programs illustrate the from() method:Program 1 : Java // Java program to demonstrate the from() method import java.time.OffsetDateTime; import java.time.ZonedDateTime; public class GFG { public static void main(String[] args) { // Function used OffsetDateTime date = OffsetDateTime.from(ZonedDateTime.now()); // Prints the date System.out.println(date); } } Output: 2018-12-12T08:24:12.442Z Program 2 : Java // Java program to demonstrate the from() method import java.time.OffsetDateTime; import java.time.ZonedDateTime; public class GFG { public static void main(String[] args) { // Function used OffsetDateTime date = OffsetDateTime.from(ZonedDateTime.now()); // Prints the date System.out.println(date); } } Output: 2018-12-12T08:24:15.077Z Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#from-java.time.temporal.TemporalAccessor- Comment More infoAdvertise with us Next Article OffsetDateTime from() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-time package Java-OffsetDateTime Practice Tags : Java Similar Reads OffsetTime from() method in Java with examples 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 1 min read OffsetDateTime format() method in Java with examples The format() method of OffsetDateTime class in Java formats this date-time using the specified formatter. Syntax : public String format(DateTimeFormatter formatter) Parameter : This method accepts a single parameter formatter which specifies the formatter to use, not null.Return Value: It returns th 1 min read OffsetDateTime get() method in Java with examples The get() method of OffsetDateTime class in Java gets the value of the specified field from this date as an int. Syntax : public int get(TemporalField field) Parameter : This method accepts a single parameter field which specifies the field to get, not null.Return Value: It returns the value for the 2 min read OffsetDateTime of() method in Java with Examples The of(int year, int month, int day, int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetDateTime class in Java is used to create an instance of OffsetDateTime from the passed values of year, month, day, hour, minute, second, nanosecond and offset. In this method 3 min read OffsetDateTime getHour() method in Java with examples The getHour() method of OffsetDateTime class in Java gets the hour-of-day field. Syntax : public int getHour() Parameter : This method accepts does not accepts any parameter. Return Value: It returns the hour-of-day which ranges from 0 to 23. Below programs illustrate the getHour() method: Program 1 1 min read Like