Class java.util.Date
All Packages This Package Previous Next
Class java.util.Date
java.lang.Object
|
+----java.util.Date
-
public class
Date
-
extends Object
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 broken down
according to the local time zone into
year, month, day, ...
-
Version:
-
1.11, 12 May 1995
-
Author:
-
James Gosling, Arthur van Hoff
-
Date()
-
Creates today's date/time.
-
Date(long)
-
Creates a date.
-
Date(int, int, int)
-
Creates a date.
-
Date(int, int, int, int, int)
-
Creates a date.
-
Date(int, int, int, int, int, int)
-
Creates a date.
-
after(Date)
-
Checks whether this date comes after another date.
-
before(Date)
-
Checks whether this date comes before another date.
-
equals(Object)
-
Compares this object against some other object.
-
getDate()
-
Return the day of the month.
-
getDay()
-
Returns the day of the week.
-
getHours()
-
Returns the hour.
-
getMinutes()
-
Returns the minute.
-
getMonth()
-
Returns the month.
-
getSeconds()
-
Returns the second.
-
getTime()
-
-
getYear()
-
Returns the year after 1900.
-
hashCode()
-
Computes a hashCode.
-
setDate(byte)
-
Sets the date.
-
setDay(byte)
-
Sets the day of the week.
-
setHours(byte)
-
Sets the hours.
-
setMinutes(byte)
-
Sets the minutes.
-
setMonth(byte)
-
Sets the month.
-
setSeconds(byte)
-
Sets the seconds.
-
setYear(int)
-
Sets the year.
-
toGMTString()
-
Converts a date to a string, using the Internet GMT conventions.
-
toLocaleString()
-
Converts a date to a string, using the locale's conventions.
-
toString()
-
Converts a date to a string, using the UNIX ctime conventions.
Date
public Date()
-
Creates today's date/time.
Date
public Date(long V)
-
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
Date
public Date(int year,
int month,
int date)
-
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
Date
public Date(int year,
int month,
int date,
int hrs,
int min)
-
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
Date
public Date(int year,
int month,
int date,
int hrs,
int min,
int sec)
-
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
getYear
public int getYear()
-
Returns the year after 1900.
setYear
public void setYear(int v)
-
Sets the year.
getMonth
public int getMonth()
-
Returns the month. ie: 0-11
setMonth
public void setMonth(byte v)
-
Sets the month.
getDate
public int getDate()
-
Return the day of the month. ie: 1-31
setDate
public void setDate(byte v)
-
Sets the date.
getDay
public int getDay()
-
Returns the day of the week. ie: 0-6
setDay
public void setDay(byte v)
-
Sets the day of the week.
getHours
public int getHours()
-
Returns the hour. ie: 0-23
setHours
public void setHours(byte v)
-
Sets the hours.
getMinutes
public int getMinutes()
-
Returns the minute. ie: 0-59
setMinutes
public void setMinutes(byte v)
-
Sets the minutes.
getSeconds
public int getSeconds()
-
Returns the second. ie: 0-59
setSeconds
public void setSeconds(byte v)
-
Sets the seconds.
getTime
public long getTime()
before
public boolean before(Date when)
-
Checks whether this date comes before another date.
after
public boolean after(Date when)
-
Checks whether this date comes after another date.
equals
public boolean equals(Object obj)
-
Compares this object against some other object.
-
Parameters:
-
obj
-
the object to compare with
-
Returns:
-
true if the object is the same
-
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, using the UNIX ctime conventions.
-
Overrides:
-
toString in class Object
toLocaleString
public String toLocaleString()
-
Converts a date to a string, using the locale's conventions.
toGMTString
public String toGMTString()
-
Converts a date to a string, using the Internet GMT conventions.
All Packages This Package Previous Next