Javatpoint Logo
Javatpoint Logo

Java OffsetTime Class

Java OffsetTime class is an immutable date-time object that represents a time, often viewed as hour-minute-second offset. It inherits Object class and implements the Comparable interface.

Java OffsetTime Class Declaration

Let's see the declaration of java.time.OffsetTime class.

Methods of Java OffsetTime Class

Method Description
String format(DateTimeFormatter formatter) It is used to format this time using the specified formatter.
int get(TemporalField field) It is used to get the value of the specified field from this time as an int.
int getHour() It is used to get the hour-of-day field.
int getMinute() It is used to get the minute-of-hour field.
int getSecond() It is used to get the second-of-minute field.
static OffsetTime now() It is used to obtain the current time from the system clock in the default time-zone.
static OffsetTime of(LocalTime time, ZoneOffset offset) It is used to obtain an instance of OffsetTime from a local time and an offset.
ValueRange range(TemporalField field) It is used to get the range of valid values for the specified field.
VLocalTime toLocalTime() It is used to get the LocalTime part of this date-time.
boolean isAfter(OffsetTime other) It checks if the instant of this OffsetTime is after that of the specified time applying both times to a common date.
boolean isBefore(OffsetTime other) It checks if the instant of this OffsetTime is before that of the specified time applying both times to a common date.
boolean isEqual(OffsetTime other) It checks if the instant of this OffsetTime is equal to that of the specified time applying both times to a common date.
boolean isSupported(TemporalField field) It checks if the specified field is supported.
OffsetTime minus(long amountToSubtract, TemporalUnit unit) It returns a copy of this time with the specified amount subtracted.
OffsetTime minus(TemporalAmount amountToSubtract) It returns a copy of this time with the specified amount subtracted.
OffsetTime minusHours(long hoursToSubtract) It returns a copy of this OffsetTime with the specified number of hours subtracted.
OffsetTime minusMinutes(long minutesToSubtract) It returns a copy of this OffsetTime with the specified number of minutes subtracted.
OffsetTime minusNanos(long nanos) It returns a copy of this OffsetTime with the specified number of nanoseconds subtracted.
OffsetTime minusSeconds(long seconds) It returns a copy of this OffsetTime with the specified number of seconds subtracted.
static OffsetTime of(int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) It obtains an instance of OffsetTime from an hour, minute, second, nanosecond and an offset.
static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) It obtains an instance of OffsetTime from a text string using a specific formatter.

Java OffsetTime Class Example

OffsetTimeExample1.java

Test it Now

Output:

16
970
58224

Java OffsetTime Class Example: getHour()

OffsetTimeExample2.java

Test it Now

Output:

15 hour

Java OffsetTime Class Example: getMinute()

OffsetTimeExample3.java

Test it Now

Output:

24 minute

Java OffsetTime Class Example: getSecond()

OffsetTimeExample4.java

Test it Now

Output:

8 second






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA