Date objects represent a single point in time. The Date class declares the programmatic interface for specific and relative time values.
Date is an abstract class that provides behavior for creating dates, comparing dates, representing dates, computing intervals, and similar functionality. It presents a programmatic interface through which suitable date objects are requested and returned. Date objects returned from Date are lightweight and immutable since they represent a invariant point in time. This class is designed to provide the foundation for arbitrary calendrical representations. Its subclass CalendarDate offers date objects that are suitable for representing dates according to western calendrical systems.
"Date" as used above implies clock time as well. The standard unit of time for date objects is a value expressed as seconds. This type makes possible a wide and fine-grained range of date and time values, giving accuracy within milliseconds for dates 10,000 years apart.
Date and its subclasses compute time as seconds relative to an absolute reference date. This reference date is the first instant of 1 January, 2001, Greenwich Mean Time (GMT). Date converts all date and time representations to and from values that are relative to this absolute reference date. A positive interval relative to a date represents a point in the future, a negative interval represents a time in the past.
Conventional UNIX systems implement time according to the Network Time Protocol (NTP) standard, which is based on Coordinated Universal Time. The current private implementations of Date follow the NTP standard. However, they do not account for leap seconds and therefore are not synchronized with International Atomic Time (the most accurate).
Like various other next.util classes, Date enables you to obtain operating-system functionality (dates and times) without depending on operating-system internals.
Date's sole primitive method, timeIntervalSinceReferenceDate, provides the basis for all the other methods in the Date interface. It returns a time value relative to an absolute reference date.
The timeInterval... methods set date objects relative to a particular time, which the method name describes. You specify (in seconds) how much more recent or how much more in the past you want your date object to be. To specify a date that occurs earlier than the method's reference date, use a negative number of seconds.
To compare dates, use the compare, laterDate, and earlierDate methods. These methods perform exact comparisons, which means they will detect subsecond differences between dates. You might want to compare dates with a less fine granularity. For example, you might want to consider two dates equal if they are within a minute of each other. If this is the case, use timeIntervalSinceDate to compare the two dates or use CalendarDate objects instead. Subclassing Date If you want to subclass Date to obtain behavior different than that provided by the CalendarDate subclass, you must do these things: