Java OffsetDateTime

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

 

Java OffsetDateTime class

Java OffsetDateTime class is an immutable representation of a date-time with an offset. It inherits Object class and implements the Comparable interface.

OffsetDateTime class is used to store the date and time fields, to a precision of nanoseconds.


 

Java OffsetDateTime class declaration

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

 

  1. public final class OffsetDateTime extends Object   

  2. implements Temporal, TemporalAdjuster, Comparable, Serializable  


 

Methods of Java OffsetDateTime

 

Method

Description

int get(TemporalField field)

It is used to get the value of the specified field from this date-time as an int.

int getDayOfMonth()

It is used to get the day-of-month field.

iint getDayOfYear()

It is used to get the day-of-year field.

DayOfWeek getDayOfWeek()

It is used to get the day-of-week field, which is an enum DayOfWeek.

OffsetDateTime minusDays(long days)

It is used to return a copy of this OffsetDateTime with the specified number of days subtracted.

static OffsetDateTime now()

It is used to obtain the current date-time from the system clock in the default time-zone.

OffsetDateTime plusDays(long days)

It is used to return a copy of this OffsetDateTime with the specified number of days added.

LocalDate toLocalDate()

It is used to get the LocalDate part of this date-time.

Java OffsetDateTime class Example: getDayOfMonth()

Java OffsetDateTime class Example: getDayOfYear()

Java OffsetDateTime class Example: getDayOfWeek()

Java OffsetDateTime class Example: toLocalDate()

Java OffsetDateTime class Example: minusDays()

ava OffsetDateTime class Example: plusDays()