|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Date
A wrapper for a date. This class lets you manipulate dates in a system independent way. To print today's date use:
Date d = new Date(); System.out.println("today = " + d);To find out what day corresponds to a particular date:
Date d = new Date(63, 0, 16); // January 16, 1963 System.out.println("Day of the week: " + d.getDay());The date can be set and examined according to the local time zone into the year, month, day, hour, minute and second.
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.
Constructor Summary | |
Date()
Creates today's date/time. |
|
Date(int year,
int month,
int date)
Creates a date. |
|
Date(int year,
int month,
int date,
int hrs,
int min)
Creates a date. |
|
Date(int year,
int month,
int date,
int hrs,
int min,
int sec)
Creates a date. |
|
Date(long date)
Creates a date. |
|
Date(String s)
Creates a date from a string according to the syntax accepted by parse(). |
Method Summary | |
boolean |
after(Date when)
Checks whether this date comes after the specified date. |
boolean |
before(Date when)
Checks whether this date comes before the specified date. |
boolean |
equals(Object obj)
Compares this object against the specified object. |
int |
getDate()
Returns the day of the month. |
int |
getDay()
Returns the day of the week. |
int |
getHours()
Returns the hour. |
int |
getMinutes()
Returns the minute. |
int |
getMonth()
Returns the month. |
int |
getSeconds()
Returns the second. |
long |
getTime()
Returns the time in milliseconds since the epoch. |
int |
getTimezoneOffset()
Return the time zone offset in minutes for the current locale that is appropriate for this time. |
int |
getYear()
Returns the year after 1900. |
int |
hashCode()
Computes a hashCode. |
static long |
parse(String s)
Given a string representing a time, parse it and return the time value. |
void |
setDate(int date)
Sets the date. |
void |
setHours(int hours)
Sets the hours. |
void |
setMinutes(int minutes)
Sets the minutes. |
void |
setMonth(int month)
Sets the month. |
void |
setSeconds(int seconds)
Sets the seconds. |
void |
setTime(long time)
Sets the time. |
void |
setYear(int year)
Sets the year. |
String |
toGMTString()
Converts a date to a String, using the Internet GMT conventions. |
String |
toLocaleString()
Converts a date to a String, using the locale conventions. |
String |
toString()
Converts a date to a String, using the UNIX ctime conventions. |
static long |
UTC(int year,
int month,
int date,
int hrs,
int min,
int sec)
Calculates a UTC value from YMDHMS. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Date()
public Date(long date)
date
- the value of the argument to be createdpublic Date(int year, int month, int date)
year
- a year after 1900month
- a month between 0-11date
- day of the month between 1-31public Date(int year, int month, int date, int hrs, int min)
year
- a year after 1900month
- a month between 0-11date
- day of the month between 1-31hrs
- hours between 0-23min
- minutes between 0-59public Date(int year, int month, int date, int hrs, int min, int sec)
year
- a year after 1900month
- a month between 0-11date
- day of the month between 1-31hrs
- hours between 0-23min
- minutes between 0-59sec
- seconds between 0-59public Date(String s)
Method Detail |
public static long UTC(int year, int month, int date, int hrs, int min, int sec)
year
- a year after 1900month
- a month between 0-11date
- day of the month between 1-31hrs
- hours between 0-23min
- minutes between 0-59sec
- seconds between 0-59public static long parse(String s)
public int getYear()
public void setYear(int year)
year
- the year valuepublic int getMonth()
public void setMonth(int month)
month
- the month value (0-11)public int getDate()
public void setDate(int date)
date
- the day valuepublic int getDay()
public int getHours()
public void setHours(int hours)
hours
- the hour valuepublic int getMinutes()
public void setMinutes(int minutes)
minutes
- the value of the minutespublic int getSeconds()
public void setSeconds(int seconds)
seconds
- the second valuepublic long getTime()
public void setTime(long time)
time
- The new time value in milliseconds since the epoch.public boolean before(Date when)
when
- the date to compare
public boolean after(Date when)
when
- the date to compare
public boolean equals(Object obj)
equals
in class Object
obj
- the object to compare with
Hashtable
public int hashCode()
hashCode
in class Object
Hashtable
public String toString()
toString
in class Object
public String toLocaleString()
public String toGMTString()
public int getTimezoneOffset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |