Class CalendarDate


  • public final class CalendarDate
    extends Object
    A specific date on the Gregorian calendar. A CalendarDate contains only date information.

    A CalendarDate only partially specifies an instant in the time continuum; it must be combined with a TimeOfDay and TimeZone to produce a specific instant.

    See Also:
    Date
    • Constructor Detail

      • CalendarDate

        public CalendarDate()
        Constructs an instance representing the current day in the default time zone.
      • CalendarDate

        public CalendarDate​(TimeZone tz)
        Constructs an instance representing the current day in the specified time zone.
        Parameters:
        tz - the time zone to which the current day is relative
      • CalendarDate

        public CalendarDate​(long epochDays)
        Constructs an instance representing the date occurring the specified number of days after epoch.
        Parameters:
        epochDays - the number of days elapsed since January 1, 1970
      • CalendarDate

        public CalendarDate​(int year,
                            int monthOfYear,
                            int dayOfMonth)
        Constructs an instance representing the specified date. Month values are number as they are on a calendar, starting with 1 for January.
        Parameters:
        year - the year portion of the date
        monthOfYear - the month portion of the date. Months are counted as on a calendar, starting with 1 for January.
        dayOfMonth - the day portion of the date
      • CalendarDate

        public CalendarDate​(Date date,
                            TimeZone tz)
        Constructs an instance representing the specified time in the given time zone.
        Parameters:
        date - the instant in time from which to extract date information
        tz - the time zone in which to interpret the specified instant
    • Method Detail

      • getDaysSinceEpoch

        public long getDaysSinceEpoch()
        Get the number of days elapsed since epoch.
        Returns:
        days elapsed since January 1, 1970
      • getYear

        public int getYear()
        Get the year portion of the date.
        Returns:
        the year
      • getMonthOfYear

        public int getMonthOfYear()
        Get the month portion of the date. Months are numbered as they would be on a calendar, starting with 1, representing January.
        Returns:
        the month of the year
      • getDayOfMonth

        public int getDayOfMonth()
        Get the day portion of the date.
        Returns:
        the day of the month
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • today

        public static long today()
        Gets the current date in the default time zone as days since epoch.
        Returns:
        the number of days elapsed since January 1, 1970
      • today

        public static long today​(TimeZone tz)
        Gets the current date in the specified time zone as days since epoch.
        Parameters:
        tz - the time zone relative to which to interpret the current date
        Returns:
        the number of days elapsed since January 1, 1970