Top Description Fields Constructors Methods
org.threeten.extra

public final Class OffsetDate

extends Object
implements Temporal, TemporalAdjuster, Comparable<OffsetDate>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, java.time.temporal.TemporalAdjuster, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor
Static Imports
java.time.temporal.ChronoField.EPOCH_DAY, .ChronoField.OFFSET_SECONDS, .ChronoUnit.DAYS

A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 2007-12-03+01:00.

OffsetDate is an immutable date-time object that represents a date, often viewed as year-month-day-offset. This object can also access other date fields such as day-of-year, day-of-week and week-of-year.

This class does not store or represent a time. For example, the value "2nd October 2007 +02:00" can be stored in an OffsetDate.

Implementation Requirements:

This class is immutable and thread-safe.

This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.

Field Summary

Modifier and TypeField and Description
private final LocalDate
date

The local date.

public static final OffsetDate
MAX

The maximum supported OffsetDate, '+999999999-12-31-18:00'.

public static final OffsetDate
MIN

The minimum supported OffsetDate, '-999999999-01-01+18:00'.

private final ZoneOffset
offset

The offset from UTC/Greenwich.

private static final long
SECONDS_PER_DAY

The number of seconds per day.

private static final long
serialVersionUID

Serialization version.

Constructor Summary

AccessConstructor and Description
private
OffsetDate(LocalDate
the local date, not null
date
,
ZoneOffset
the zone offset, not null
offset
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public Temporal

Returns:

the adjusted object, not null
adjustInto
(Temporal
the target object to be adjusted, not null
temporal
)

Implements java.time.temporal.TemporalAdjuster.adjustInto.

Adjusts the specified temporal object to have the same offset and date as this object.

public OffsetDateTime

Returns:

the offset date-time formed from this date and the specified time, not null
atTime
(LocalTime
the time to combine with, not null
time
)

Returns an offset date-time formed from this date at the specified time.

public int

Returns:

the comparator value, negative if less, positive if greater
compareTo
(OffsetDate
the other date to compare to, not null
other
)

Implements java.lang.Comparable.compareTo.

Compares this OffsetDate to another date.

public boolean

Returns:

true if this is equal to the other date
equals
(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Checks if this date is equal to another date.

public String

Returns:

the formatted date string, not null
format
(DateTimeFormatter
the formatter to use, not null
formatter
)

Formats this date using the specified formatter.

public static OffsetDate

Returns:

the offset date, not null
from
(TemporalAccessor
the temporal object to convert, not null
temporal
)

Obtains an instance of OffsetDate from a temporal object.

public int

Returns:

the value for the field
get
(TemporalField
the field to get, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field from this date as an int.

public int

Returns:

the day-of-month, from 1 to 31
getDayOfMonth
()

Gets the day-of-month field.

public DayOfWeek

Returns:

the day-of-week, not null
getDayOfWeek
()

Gets the day-of-week field, which is an enum DayOfWeek.

public int

Returns:

the day-of-year, from 1 to 365, or 366 in a leap year
getDayOfYear
()

Gets the day-of-year field.

public long

Returns:

the value for the field
getLong
(TemporalField
the field to get, not null
field
)

Implements java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field from this date as a long.

public Month

Returns:

the month-of-year, not null
getMonth
()

Gets the month-of-year field using the Month enum.

public int

Returns:

the month-of-year, from 1 to 12
getMonthValue
()

Gets the month-of-year field from 1 to 12.

public ZoneOffset

Returns:

the zone offset, not null
getOffset
()

Gets the zone offset, such as '+01:00'.

public int

Returns:

the year, from MIN_YEAR to MAX_YEAR
getYear
()

Gets the year field.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

A hash code for this date.

public boolean

Returns:

true if this is after the instant of the specified date
isAfter
(OffsetDate
the other date to compare to, not null
other
)

Checks if the instant of midnight at the start of this OffsetDate is after midnight at the start of the specified date.

public boolean

Returns:

true if this is before the instant of the specified date
isBefore
(OffsetDate
the other date to compare to, not null
other
)

Checks if the instant of midnight at the start of this OffsetDate is before midnight at the start of the specified date.

public boolean

Returns:

true if the instant equals the instant of the specified date
isEqual
(OffsetDate
the other date to compare to, not null
other
)

Checks if the instant of midnight at the start of this OffsetDate equals midnight at the start of the specified date.

public boolean

Returns:

true if the field is supported on this date, false if not
isSupported
(TemporalField
the field to check, null returns false
field
)

Implements java.time.temporal.TemporalAccessor.isSupported.

Checks if the specified field is supported.

public boolean

Returns:

true if the unit can be added/subtracted, false if not
isSupported
(TemporalUnit
the unit to check, null returns false
unit
)

Implements java.time.temporal.Temporal.isSupported.

Checks if the specified unit is supported.

public OffsetDate

Returns:

an OffsetDate based on this date with the subtraction made, not null
minus
(TemporalAmount
the amount to subtract, not null
amountToSubtract
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this date with the specified amount subtracted.

public OffsetDate

Returns:

an OffsetDate based on this date with the specified amount subtracted, not null
minus
(long
the amount of the unit to subtract from the result, may be negative
amountToSubtract
,
TemporalUnit
the unit of the amount to subtract, not null
unit
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this date with the specified amount subtracted.

public OffsetDate

Returns:

an OffsetDate based on this date with the days subtracted, not null
minusDays
(long
the days to subtract, may be negative
days
)

Returns a copy of this OffsetDate with the specified number of days subtracted.

public OffsetDate

Returns:

an OffsetDate based on this date with the months subtracted, not null
minusMonths
(long
the months to subtract, may be negative
months
)

Returns a copy of this OffsetDate with the specified number of months subtracted.

public OffsetDate

Returns:

an OffsetDate based on this date with the weeks subtracted, not null
minusWeeks
(long
the weeks to subtract, may be negative
weeks
)

Returns a copy of this OffsetDate with the specified number of weeks subtracted.

public OffsetDate

Returns:

an OffsetDate based on this date with the years subtracted, not null
minusYears
(long
the years to subtract, may be negative
years
)

Returns a copy of this OffsetDate with the specified number of years subtracted.

public static OffsetDate

Returns:

the current date using the system clock, not null
now
()

Obtains the current date from the system clock in the default time-zone.

public static OffsetDate

Returns:

the current date using the system clock, not null
now
(ZoneId
the zone ID to use, not null
zone
)

Obtains the current date from the system clock in the specified time-zone.

public static OffsetDate

Returns:

the current date, not null
now
(Clock
the clock to use, not null
clock
)

Obtains the current date from the specified clock.

public static OffsetDate

Returns:

the offset date, not null
of
(LocalDate
the local date, not null
date
,
ZoneOffset
the zone offset, not null
offset
)

Obtains an instance of OffsetDate from a local date and an offset.

public static OffsetDate

Returns:

the offset date, not null
of
(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
int
the month-of-year to represent, from 1 (January) to 12 (December)
month
,
int
the day-of-month to represent, from 1 to 31
dayOfMonth
,
ZoneOffset
the zone offset, not null
offset
)

Obtains an instance of OffsetDate from a year, month, day and offset.

public static OffsetDate

Returns:

the offset time, not null
ofInstant
(Instant
the instant to create the time from, not null
instant
,
ZoneId
the time-zone, which may be an offset, not null
zone
)

Obtains an instance of OffsetDate from an Instant and zone ID.

This creates an offset date with the same instant as midnight at the start of day of the instant specified.

public static OffsetDate

Returns:

the parsed offset date, not null
parse
(CharSequence
the text to parse such as "2007-12-03+01:00", not null
text
)

Obtains an instance of OffsetDate from a text string such as 2007-12-03+01:00.

public static OffsetDate

Returns:

the parsed offset date, not null
parse
(CharSequence
the text to parse, not null
text
,
DateTimeFormatter
the formatter to use, not null
formatter
)

Obtains an instance of OffsetDate from a text string using a specific formatter.

public OffsetDate

Returns:

an OffsetDate based on this date with the addition made, not null
plus
(TemporalAmount
the amount to add, not null
amountToAdd
)

Overrides default java.time.temporal.Temporal.plus.

Returns a copy of this date with the specified period added.

public OffsetDate

Returns:

an OffsetDate based on this date with the specified amount added, not null
plus
(long
the amount of the unit to add to the result, may be negative
amountToAdd
,
TemporalUnit
the unit of the amount to add, not null
unit
)

Implements java.time.temporal.Temporal.plus.

Returns a copy of this date with the specified amount added.

public OffsetDate

Returns:

an OffsetDate based on this date with the days added, not null
plusDays
(long
the days to add, may be negative
days
)

Returns a copy of this OffsetDate with the specified number of days added.

public OffsetDate

Returns:

an OffsetDate based on this date with the months added, not null
plusMonths
(long
the months to add, may be negative
months
)

Returns a copy of this OffsetDate with the specified number of months added.

public OffsetDate

Returns:

an OffsetDate based on this date with the weeks added, not null
plusWeeks
(long
the weeks to add, may be negative
weeks
)

Returns a copy of this OffsetDate with the specified number of weeks added.

public OffsetDate

Returns:

an OffsetDate based on this date with the years added, not null
plusYears
(long
the years to add, may be negative
years
)

Returns a copy of this OffsetDate with the specified number of years added.

public <
the type of the result
R
>
R

Returns:

the query result, null may be returned (defined by the query)
query
(TemporalQuery<R>
the query to invoke, not null
query
)

Overrides default java.time.temporal.TemporalAccessor.query.

Queries this date using the specified query.

public ValueRange

Returns:

the range of valid values for the field, not null
range
(TemporalField
the field to query the range for, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.

private Object

Returns:

the valid object, not null
readResolve
()

Validates the input.

private long

Returns:

the epoch seconds value
toEpochSecond
()

Converts this date to midnight at the start of day in epoch seconds.

public long

Returns:

the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative
toEpochSecond
(LocalTime
the local time, not null
time
)

Converts this OffsetDate to the number of seconds since the epoch of 1970-01-01T00:00:00Z.

public LocalDate

Returns:

the date part of this date, not null
toLocalDate
()

Gets the LocalDate part of this date.

public String

Returns:

a string representation of this date, not null
toString
()

Overrides java.lang.Object.toString.

Outputs this date as a String, such as 2007-12-03+01:00.

public long

Returns:

the amount of time between this date and the end date
until
(Temporal
the end time, exclusive, which is converted to an OffsetDate, not null
endExclusive
,
TemporalUnit
the unit to measure the amount in, not null
unit
)

Implements java.time.temporal.Temporal.until.

Calculates the period between this date and another date in terms of the specified unit.

private OffsetDate
with(LocalDate
the date to create with, not null
date
,
ZoneOffset
the zone offset to create with, not null
offset
)

Returns a new date based on this one, returning this where possible.

public OffsetDate

Returns:

an OffsetDate based on this with the adjustment made, not null
with
(TemporalAdjuster
the adjuster to use, not null
adjuster
)

Overrides default java.time.temporal.Temporal.with.

Returns an adjusted copy of this date.

public OffsetDate

Returns:

an OffsetDate based on this with the specified field set, not null
with
(TemporalField
the field to set in the result, not null
field
,
long
the new value of the field in the result
newValue
)

Implements java.time.temporal.Temporal.with.

Returns a copy of this date with the specified field set to a new value.

public OffsetDate

Returns:

an OffsetDate based on this date with the requested day, not null
withDayOfMonth
(int
the day-of-month to set in the result, from 1 to 28-31
dayOfMonth
)

Returns a copy of this OffsetDate with the day-of-month altered.

public OffsetDate

Returns:

an OffsetDate based on this date with the requested day, not null
withDayOfYear
(int
the day-of-year to set in the result, from 1 to 365-366
dayOfYear
)

Returns a copy of this OffsetDate with the day-of-year altered.

public OffsetDate

Returns:

an OffsetDate based on this date with the requested month, not null
withMonth
(int
the month-of-year to set in the result, from 1 (January) to 12 (December)
month
)

Returns a copy of this OffsetDate with the month-of-year altered.

public OffsetDate

Returns:

an OffsetDate based on this date with the requested offset, not null
withOffsetSameLocal
(ZoneOffset
the zone offset to change to, not null
offset
)

Returns a copy of this OffsetDate with the specified offset ensuring that the result has the same local date.

public OffsetDate

Returns:

an OffsetDate based on this date with the requested year, not null
withYear
(int
the year to set in the result, from MIN_YEAR to MAX_YEAR
year
)

Returns a copy of this OffsetDate with the year altered.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait