Class Date

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Date>, Freezable

    public class Date
    extends java.sql.Date
    implements Freezable
    Date with database semantics.

    Differs from java.sql.Date when serialized/deserialized in different timezones. Databases don't provide a time and therefore no timezone for a date, i.e. when sent over wire to different locations a date should always remain the same for all timezones. In java.sql.Data, however, the epochal time is serialized which may lead to a different date when deserialized in another timezone. In Date the effective date is serialized as YYYYMMDD to provide the same semantics as databases do.

    Furthermore, tentackle dates can be frozen, i.e. made immutable.

    Author:
    harald
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Date()
      Creates the current date.
      Date​(long date)
      Constructs a Date object using the given milliseconds time value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Date clone()
      static Date createFrozen​(long epoch)
      Creates a frozen date.
      void freeze()
      Makes this object immutable.
      java.util.Calendar getCalendar()
      Gets the calendar for this date.
      void setDate​(int date)
      Deprecated.
      void setHours​(int hours)
      Deprecated.
      void setMinutes​(int minutes)
      Deprecated.
      void setMonth​(int month)
      Deprecated.
      void setSeconds​(int seconds)
      Deprecated.
      void setTime​(long date)
      void setYear​(int year)
      Deprecated.
      • Methods inherited from class java.sql.Date

        getHours, getMinutes, getSeconds, toInstant, toLocalDate, toString, valueOf, valueOf
      • Methods inherited from class java.util.Date

        after, before, compareTo, equals, from, getDate, getDay, getMonth, getTime, getTimezoneOffset, getYear, hashCode, parse, toGMTString, toLocaleString, UTC
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Date

        public Date​(long date)
        Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.
        Parameters:
        date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.
      • Date

        public Date()
        Creates the current date.
    • Method Detail

      • createFrozen

        public static Date createFrozen​(long epoch)
        Creates a frozen date.
        Parameters:
        epoch - epochal milliseconds since January 1, 1970, 00:00:00 GMT
        Returns:
        the frozen date
      • clone

        public Date clone()

        Cloned dates are always not frozen.

        Overrides:
        clone in class java.util.Date
      • getCalendar

        public java.util.Calendar getCalendar()
        Gets the calendar for this date.
        Returns:
        the calendar
      • freeze

        public void freeze()
        Description copied from interface: Freezable
        Makes this object immutable.
        Specified by:
        freeze in interface Freezable
      • setTime

        public void setTime​(long date)

        Overridden to clear the lazy calendar and to check for frozen.

        Overrides:
        setTime in class java.sql.Date
      • setYear

        @Deprecated
        public void setYear​(int year)
        Deprecated.
        Overrides:
        setYear in class java.util.Date
      • setMonth

        @Deprecated
        public void setMonth​(int month)
        Deprecated.
        Overrides:
        setMonth in class java.util.Date
      • setDate

        @Deprecated
        public void setDate​(int date)
        Deprecated.
        Overrides:
        setDate in class java.util.Date
      • setHours

        @Deprecated
        public void setHours​(int hours)
        Deprecated.
        Overrides:
        setHours in class java.sql.Date
      • setMinutes

        @Deprecated
        public void setMinutes​(int minutes)
        Deprecated.
        Overrides:
        setMinutes in class java.sql.Date
      • setSeconds

        @Deprecated
        public void setSeconds​(int seconds)
        Deprecated.
        Overrides:
        setSeconds in class java.sql.Date