    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class java.util.Date

    java.lang.Object
       |
       +----java.util.Date

public class Date
extends Object
implements Serializable, Cloneable

A wrapper for a date. Date objects represent a specific instant in time with millisecond precision.

Prior to JDK 1.1 the class Date had two additional functions. It allowed the interpretation of dates as year, month, day, hour, minute and second values. It also allowed the formatting and parsing of date strings. Unfortunately, the API for these functions was not amenable to Internationalization. As of JDK 1.1, the Calendar class should be used to convert between dates and time fields and the DateFormat class should be used to format and parse date strings. The corresponding methods in Date are deprecated.

While the API is intended to reflect UTC, Coordinated Universal Time, it doesn't do so exactly. This inexact behavior is inherited from the time system of the underlying OS. All modern OS's that I (jag) am aware of assume that 1 day = 24*60*60 seconds. In UTC, about once a year there is an extra second, called a "leap second" added to a day to account for the wobble of the earth. Most computer clocks are not accurate enough to be able to reflect this distinction. Some computer standards are defined in GMT, which is equivalent to UT, Universal Time. GMT is the "civil" name for the standard, UT is the "scientific" name for the same standard. The distinction between UTC and UT is that the first is based on an atomic clock and the second is based on astronomical observations, which for all practical purposes is an invisibly fine hair to split. An interesting source of further information is the US Naval Observatory, particularly the Directorate of Time and their definitions of Systems of Time.

See Also:
  Calendar, DateFormat, TimeZone

##

Date()
  Creates today's date/time.
Date(int, int, int)
  Creates a date. Deprecated.
Date(int, int, int, int, int)
  Creates a date. Deprecated.
Date(int, int, int, int, int, int)
  Creates a date. Deprecated.
Date(long)
  Creates a date.
Date(String)
  Creates a date from a string according to the syntax accepted by parse(). Deprecated.

##

after(Date)
  Checks whether this date comes after the specified date.
before(Date)
  Checks whether this date comes before the specified date.
equals(Object)
  Compares this object against the specified object.
getDate()
  Returns the day of the month. Deprecated.
getDay()
  Returns the day of the week. Deprecated.
getHours()
  Returns the hour. Deprecated.
getMinutes()
  Returns the minute. Deprecated.
getMonth()
  Returns the month. Deprecated.
getSeconds()
  Returns the second. Deprecated.
getTime()
  Returns the time in milliseconds since the epoch.
getTimezoneOffset()
  Return the time zone offset in minutes for the current locale that is appropriate for this time. Deprecated.
getYear()
  Returns the year after 1900. Deprecated.
hashCode()
  Computes a hashCode.
parse(String)
  Given a string representing a time, parse it and return the time value. Deprecated.
setDate(int)
  Sets the date. Deprecated.
setHours(int)
  Sets the hours. Deprecated.
setMinutes(int)
  Sets the minutes. Deprecated.
setMonth(int)
  Sets the month. Deprecated.
setSeconds(int)
  Sets the seconds. Deprecated.
setTime(long)
  Sets the time.
setYear(int)
  Sets the year. Deprecated.
toGMTString()
  Converts a date to a String, using the Internet GMT conventions. Deprecated.
toLocaleString()
  Converts a date to a String, using the locale conventions. Deprecated.
toString()
  Converts a date to a String of the form like: "Sat Aug 12 02:30:00 PDT 1995"
UTC(int, int, int, int, int, int)
  Calculates a UTC value from YMDHMS. Deprecated.

##

Date

      public Date()

  Creates today's date/time.

Date

      public Date(long date)

  Creates a date.

  Parameters:
    date - milliseconds from the epoch (00:00:00 GMT Jan 1, 1970). Negative values represent dates prior to the epoch.

Date

      public Date(int year,
                  int month,
                  int date)

  Note: Date() is deprecated.

  Creates a date. The fields are normalized before the Date object is created. The arguments do not have to be in the correct range. For example, the 32nd of January is correctly interpreted as the 1st of February. You can use this to figure out what day a particular date falls on.

  Parameters:
    year - a year after 1900
    month - a month between 0-11
    date - day of the month between 1-31
  See Also:
    Calendar

Date

      public Date(int year,
                  int month,
                  int date,
                  int hrs,
                  int min)

  Note: Date() is deprecated.

  Creates a date. The fields are normalized before the Date object is created. The arguments do not have to be in the correct range. For example, the 32nd of January is correctly interpreted as the 1st of February. You can use this to figure out what day a particular date falls on.

  Parameters:
    year - a year after 1900
    month - a month between 0-11
    date - day of the month between 1-31
    hrs - hours between 0-23
    min - minutes between 0-59
  See Also:
    Calendar

Date

      public Date(int year,
                  int month,
                  int date,
                  int hrs,
                  int min,
                  int sec)

  Note: Date() is deprecated.

  Creates a date. The fields are normalized before the Date object is created. The arguments do not have to be in the correct range. For example, the 32nd of January is correctly interpreted as the 1st of February. You can use this to figure out what day a particular date falls on.

  Parameters:
    year - a year after 1900
    month - a month between 0-11
    date - day of the month between 1-31
    hrs - hours between 0-23
    min - minutes between 0-59
    sec - seconds between 0-59
  See Also:
    Calendar

Date

      public Date(String s)

  Note: Date() is deprecated.

  Creates a date from a string according to the syntax accepted by parse().

  See Also:
    DateFormat

##

UTC

      public static long UTC(int year,
                             int month,
                             int date,
                             int hrs,
                             int min,
                             int sec)

  Note: UTC() is deprecated.

  Calculates a UTC value from YMDHMS. Interpretes the parameters in UTC, not in the local time zone.

  Parameters:
    year - a year after 1900
    month - a month between 0-11
    date - day of the month between 1-31
    hrs - hours between 0-23
    min - minutes between 0-59
    sec - seconds between 0-59
  See Also:
    Calendar

parse

      public static long parse(String s)

  Note: parse() is deprecated.

  Given a string representing a time, parse it and return the time value. It accepts many syntaxes, but most importantly, in accepts the IETF standard date syntax: "Sat, 12 Aug 1995 13:30:00 GMT". It understands the continental US time zone abbreviations, but for general use, a timezone offset should be used: "Sat, 12 Aug 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If no time zone is specified, the local time zone is assumed. GMT and UTC are considered equivalent.

  See Also:
    DateFormat

getYear

      public int getYear()

  Note: getYear() is deprecated.

  Returns the year after 1900.

  See Also:
    Calendar

setYear

      public void setYear(int year)

  Note: setYear() is deprecated.

  Sets the year.

  Parameters:
    year - the year value
  See Also:
    Calendar

getMonth

      public int getMonth()

  Note: getMonth() is deprecated.

  Returns the month. This method assigns months with the values 0-11, with January beginning at value 0.

  See Also:
    Calendar

setMonth

      public void setMonth(int month)

  Note: setMonth() is deprecated.

  Sets the month.

  Parameters:
    month - the month value (0-11)
  See Also:
    Calendar

getDate

      public int getDate()

  Note: getDate() is deprecated.

  Returns the day of the month. This method assigns days with the values of 1 to 31.

  See Also:
    Calendar

setDate

      public void setDate(int date)

  Note: setDate() is deprecated.

  Sets the date.

  Parameters:
    date - the day value
  See Also:
    Calendar

getDay

      public int getDay()

  Note: getDay() is deprecated.

  Returns the day of the week. This method assigns days of the week with the values 0-6, with 0 being Sunday.

  See Also:
    Calendar

getHours

      public int getHours()

  Note: getHours() is deprecated.

  Returns the hour. This method assigns the value of the hours of the day to range from 0 to 23, with midnight equal to 0.

  See Also:
    Calendar

setHours

      public void setHours(int hours)

  Note: setHours() is deprecated.

  Sets the hours.

  Parameters:
    hours - the hour value
  See Also:
    Calendar

getMinutes

      public int getMinutes()

  Note: getMinutes() is deprecated.

  Returns the minute. This method assigns the minutes of an hour to be any value from 0 to 59.

  See Also:
    Calendar

setMinutes

      public void setMinutes(int minutes)

  Note: setMinutes() is deprecated.

  Sets the minutes.

  Parameters:
    minutes - the value of the minutes
  See Also:
    Calendar

getSeconds

      public int getSeconds()

  Note: getSeconds() is deprecated.

  Returns the second. This method assigns the seconds of a minute to values of 0-59.

  See Also:
    Calendar

setSeconds

      public void setSeconds(int seconds)

  Note: setSeconds() is deprecated.

  Sets the seconds.

  Parameters:
    seconds - the second value
  See Also:
    Calendar

getTime

      public long getTime()

  Returns the time in milliseconds since the epoch.

setTime

      public void setTime(long time)

  Sets the time.

  Parameters:
    time - The new time value in milliseconds since the epoch.

before

      public boolean before(Date when)

  Checks whether this date comes before the specified date.

  Parameters:
    when - the date to compare
  Returns:
    true if the original date comes before the specified one; false otherwise.

after

      public boolean after(Date when)

  Checks whether this date comes after the specified date.

  Parameters:
    when - the date to compare
  Returns:
    true if the original date comes after the specified one; false otherwise.

equals

      public boolean equals(Object obj)

  Compares this object against the specified object.

  Parameters:
    obj - the object to compare with
  Returns:
    true if the objects are the same; false otherwise.
  Overrides:
    equals in class Object

hashCode

      public int hashCode()

  Computes a hashCode.

  Overrides:
    hashCode in class Object

toString

      public String toString()

  Converts a date to a String of the form like: "Sat Aug 12 02:30:00 PDT 1995"

  Overrides:
    toString in class Object

toLocaleString

      public String toLocaleString()

  Note: toLocaleString() is deprecated.

  Converts a date to a String, using the locale conventions.

  See Also:
    DateFormat

toGMTString

      public String toGMTString()

  Note: toGMTString() is deprecated.

  Converts a date to a String, using the Internet GMT conventions.

  See Also:
    DateFormat

getTimezoneOffset

      public int getTimezoneOffset()

  Note: getTimezoneOffset() is deprecated.

  Return the time zone offset in minutes for the current locale that is appropriate for this time. This value would be a constant except for daylight savings time.

  See Also:
    Calendar, TimeZone

    All Packages  Class Hierarchy  This Package  Previous  Next  Index