Class OffsetDate

  • All Implemented Interfaces:
    Serializable, Comparable<OffsetDate>

    public final class OffsetDate
    extends Object
    implements Serializable, Comparable<OffsetDate>
    A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 2007-12-03+01:00.

    The class is merely a thin wrapper around OffsetDateTime because a date-only class is missing from JDK. The class exist mainly for the purpose of JAXB mapping to/from XML Schema type xs:date.

    This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of OffsetDate may have unpredictable results and should be avoided. The equals method should be used for comparisons.

    This class is immutable and thread-safe.

    See Also:
    Serialized Form
    • Method Detail

      • of

        public static OffsetDate of​(int year,
                                    int month,
                                    int dayOfMonth,
                                    ZoneOffset offset)
        Obtains an instance of OffsetDate from a year, month, day, and offset.
        Parameters:
        year - the year to represent, for example 2018.
        month - the month-of-year to represent, from 1 (January) to 12 (December)
        dayOfMonth - the day-of-month to represent, from 1 to 31
        offset - the zone offset, not null
        Returns:
        a date, not null
        See Also:
        OffsetDateTime.of(int, int, int, int, int, int, int, java.time.ZoneOffset)
      • of

        public static OffsetDate of​(OffsetDateTime datetime)
        Obtains an instance of OffsetDate from an OffsetDateTime The time part of the input value will be removed.
        Parameters:
        datetime - datetime value, not null
        Returns:
        a date, not null
      • getDate

        public OffsetDateTime getDate()
        Gets the date value.
        Returns:
        datetime value with time part set to midnight, never null
      • hashCode

        public int hashCode()
        A hash code for this date.
        Overrides:
        hashCode in class Object
        Returns:
        a suitable hash code
      • equals

        public boolean equals​(Object obj)
        Checks if this date is equal to another date.

        The comparison is delegated to the wrapped OffsetDateTime. To compare for the same instant on the time-line, use getDate().isEqual(). Only objects of type OffsetDate are compared, other types return false.

        Overrides:
        equals in class Object
        Parameters:
        obj - the object to check, null returns false
        Returns:
        true if this is equal to the other date
        See Also:
        OffsetDateTime.equals(java.lang.Object)
      • from

        public static OffsetDate from​(TemporalAccessor temporal)
        Obtains an instance of OffsetDate from a temporal object.

        This obtains an offset date based on the specified temporal. A TemporalAccessor represents an arbitrary set of date and time information, which this factory converts to an instance of OffsetDate. Any time information in the temporal will be ignored.

        The conversion will first obtain a ZoneOffset from the temporal object. It will then try to obtain a LocalDate, falling back to an Instant if necessary. The result will be the combination of ZoneOffset with either with LocalDate or Instant.

        This method matches the signature of the functional interface TemporalQuery allowing it to be used as a query via method reference, OffsetDate::from.

        Parameters:
        temporal - the temporal object to convert, not null
        Returns:
        the offset date, not null
        Throws:
        DateTimeException - if unable to convert to an OffsetDate