OffsetDateTime of() method in Java with Examples Last Updated : 05 Jun, 2020 Comments Improve Suggest changes Like Article Like Report 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, the value of the year, month, day, hour, minute, second and nano-second is passed in integer format and the method returns date-time on the basis of these values. Syntax: public static OffsetDateTime of(int year, int month, int day, int hour, int minute, int second, int nanosecond, ZoneOffset offset) Parameters: This method accepts eight parameters. year - It is of Integer type and represents the year. It varies from MIN_YEAR to MAX_YEAR. month - It is of Integer type and represents the month of the year. It varies from 1(JANUARY) to 12(DECEMBER). day - It is of Integer type and represents the day of the month. It varies from 1 to 31. hour - It is of Integer type and represents the hour of the day. It varies from 0 to 23. minute - It is of Integer type and represents the minute of the hour. It varies from 0 to 59. second - It is of Integer type and represents the second of the minute. It varies from 0 to 59. nanosecond - It is of Integer type and represents the nanosecond. It varies from 0 to 999999999. offset - It is of ZoneOffset type and represents the zone offset. It should not be null. Return value: This method returns the OffsetDateTime. Exception: This method throws DateTimeException if any field value is out of range or the day of the month is invalid for the month-year. Below programs illustrate the of() method of OffsetDateTime class in Java: Program 1: Java // Java program to demonstrate // OffsetDateTime of() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main( String[] args) { // Create OffsetDateTime object OffsetDateTime offsetdatetime = OffsetDateTime.of( 2020, 5, 20, 9, 10, 40, 50000, ZoneOffset.UTC); // Print date-time System.out.println( "DATE-TIME: " + offsetdatetime); } } Output: DATE-TIME: 2020-05-20T09:10:40.000050Z Program 2: Java // Java program to demonstrate // OffsetDateTime of() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Create OffsetDateTime object OffsetDateTime offsetdatetime = OffsetDateTime.of( 2020, 5, 20, 9, 10, 40, 20000, ZoneOffset.ofHoursMinutes( 5, 30)); // Print date-time System.out.println( "DATE-TIME: " + offsetdatetime); } } Output: DATE-TIME: 2020-05-20T09:10:40.000020+05:30 References: https://docs.oracle.com/javase/10/docs/api/java/time/OffsetDateTime.html#of(int, int, int, int, int, int, int, java.time.ZoneOffset) Comment More infoAdvertise with us Next Article OffsetDateTime of() method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-OffsetDateTime Practice Tags : Java Similar Reads OffsetDateTime now() method in Java with Example The now() method of the OffsetDateTime class in Java is used to obtain the current offset date-time using the system clock. This is done after querying the system clock in the default time zone. The method uses the hardcoded clock for testing instead of the alternative clock. Syntax: public static O 3 min read OffsetTime of() method in Java with Examples The of(int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetTime class in Java is used to create an instance of OffsetTime from the passed values of hour, minute, second and nanosecond. In this method, we pass the value of hour, minute, second and nanosecond in in 2 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 OffsetTime now() method in Java with examples The now() method of OffsetTime class in Java obtains the current time from the system clock in the default time-zone. Syntax : public static OffsetTime now() Parameter: This method does not accepts any parameter. Return Value: It returns the current time using the system clock and default time-zone 2 min read OffsetDateTime from() method in Java with examples 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.Re 1 min read OffsetDateTime query() method in Java with Examples query() method of an OffsetDateTime class used to query this OffsetDateTime using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this OffsetDateTime. Syntax: public <R> R query(TemporalQuery<R> query) Pa 2 min read OffsetDateTime until() Method in Java with Examples until() method of the OffsetDateTime class used to calculate the amount of time between two OffsetDateTime objects using TemporalUnit. The start and end points are this and the specified OffsetDateTime passed as a parameter. The result will be negative if the end is before the start. The calculation 2 min read OffsetDateTime with() Method in Java with Examples In OffsetDateTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the OffsetDateTime class used to adjusted this OffsetDateTime using TemporalAdjuster and after adjustment returns the co 3 min read OffsetDateTime range() method in Java with Examples The range() method of the OffsetDateTime class used to get the ValueRange object which is the range of field in terms of the minimum and maximum values for the field passed as a parameter to this method. The method returns ValueRange object only for those fields which are supported by OffsetDateTime 2 min read OffsetDateTime minusNanos() method in Java with examples The minusNanos() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of nano-seconds subtracted from the parsed date and time. Syntax: public OffsetDateTime minusNanos(long nano-seconds) Parameter: This method accepts a single parameter nano-seconds 2 min read Like