jd.util
Class Date

java.lang.Object
  extended byjd.util.Date
All Implemented Interfaces:
Cloneable

public class Date
extends Object
implements Cloneable

A class for storing date values. Easier to use than java.util.Calendar and not so deprecated as java.util.Date.


Field Summary
static int WEEKDAY_FRIDAY
           
static int WEEKDAY_MONDAY
           
static int WEEKDAY_SATURDAY
           
static int WEEKDAY_SUNDAY
           
static int WEEKDAY_THURSDAY
           
static int WEEKDAY_TUESDAY
           
static int WEEKDAY_WEDNESDAY
           
 
Constructor Summary
Date()
          Create a Date object for current date.
Date(Calendar cal)
          Create a date from a Calendar.
Date(Date date)
          Create a date from another date.
Date(Date date)
          Create a date from a java.util.Date.
Date(int year, int month, int day)
          Create a new Date.
Date(long time)
          Creates a Date object for the given system time.
 
Method Summary
 Date addDays(int days)
          Return a new Date object representing this date plus the given amount of days.
 Date addMonths(int months)
          Return a new Date object representing this date plus the given amount of months.
 Date addYears(int years)
          Return a new Date object representing this date plus the given amount of years.
 Object clone()
          Clone this date.
 int difference(Date date)
          Calculate the difference in days between two dates.
 boolean equals(Object date)
          Test if this date is equal to another date.
static Date fromInteger(int value)
          Extract a date from an integer.
 int getDay()
          Return the day value (ranging from 1 to 31).
 int getDayOfWeek()
           
 int getLastDayOfMonth()
          Returns the value for the last day of the month of this date (ranging from 28 to 31).
static int getLastDayOfMonth(int month, int year)
          Returns the last day of the month for the given month and year (ranging from 28 to 31).
 int getMonth()
          Return the month value (ranging from 1 to 12).
 int getYear()
          Return the year value.
 int hashCode()
          Get a hashcode for the date.
 boolean isAfter(Date d)
          Test if this date is after the given date.
 boolean isBefore(Date d)
          Test if this date is before the given date.
 boolean isLeapYear()
          Tests if the year of this date is a leap year.
static boolean isLeapYear(int year)
          Test if the given year is a leap year.
static boolean isValidDate(int year, int month, int day)
          Test if the given values represent a valid date.
 Calendar toCalendar()
          Convert the date to an Calendar.
static Date today()
          Return a Date object for the current date.
 int toInteger()
          Return an integer representation of this date.
static int toInteger(int day, int month, int year)
          Return an integer representation of the given date values.
 Date toJavaDate()
          Convert the date to an java.util.Date.
 Date toJavaSqlDate()
          Convert the date to an java.sql.Date.
 int toJulianDayNumber()
          Convert a date (more accurate: the noon of this date) to its Julian Day Number.
 String toString()
          Return a string representation of this date in the form yyyymmdd.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

WEEKDAY_SUNDAY

public static final int WEEKDAY_SUNDAY
See Also:
Constant Field Values

WEEKDAY_MONDAY

public static final int WEEKDAY_MONDAY
See Also:
Constant Field Values

WEEKDAY_TUESDAY

public static final int WEEKDAY_TUESDAY
See Also:
Constant Field Values

WEEKDAY_WEDNESDAY

public static final int WEEKDAY_WEDNESDAY
See Also:
Constant Field Values

WEEKDAY_THURSDAY

public static final int WEEKDAY_THURSDAY
See Also:
Constant Field Values

WEEKDAY_FRIDAY

public static final int WEEKDAY_FRIDAY
See Also:
Constant Field Values

WEEKDAY_SATURDAY

public static final int WEEKDAY_SATURDAY
See Also:
Constant Field Values
Constructor Detail

Date

public Date()
Create a Date object for current date.


Date

public Date(long time)
Creates a Date object for the given system time.


Date

public Date(int year,
            int month,
            int day)
Create a new Date.

Parameters:
year - the year (the year 2001 is specified as 2001)
month - the month (counting from 1 to 12)
day - the day (counting from 1 to 31)
Throws:
IllegalArgumentException - thrown if the values represent an invalid date

Date

public Date(Date date)
Create a date from another date.


Date

public Date(Date date)
Create a date from a java.util.Date.


Date

public Date(Calendar cal)
Create a date from a Calendar.

Method Detail

today

public static Date today()
Return a Date object for the current date.


getDay

public int getDay()
Return the day value (ranging from 1 to 31).


getMonth

public int getMonth()
Return the month value (ranging from 1 to 12).


getYear

public int getYear()
Return the year value.


getLastDayOfMonth

public int getLastDayOfMonth()
Returns the value for the last day of the month of this date (ranging from 28 to 31).


getLastDayOfMonth

public static int getLastDayOfMonth(int month,
                                    int year)
Returns the last day of the month for the given month and year (ranging from 28 to 31).


isLeapYear

public boolean isLeapYear()
Tests if the year of this date is a leap year.


isLeapYear

public static boolean isLeapYear(int year)
Test if the given year is a leap year.


getDayOfWeek

public int getDayOfWeek()

equals

public boolean equals(Object date)
Test if this date is equal to another date.


isBefore

public boolean isBefore(Date d)
Test if this date is before the given date.


isAfter

public boolean isAfter(Date d)
Test if this date is after the given date.


addYears

public Date addYears(int years)
Return a new Date object representing this date plus the given amount of years.


addMonths

public Date addMonths(int months)
Return a new Date object representing this date plus the given amount of months.


addDays

public Date addDays(int days)
Return a new Date object representing this date plus the given amount of days.


difference

public int difference(Date date)
Calculate the difference in days between two dates.


isValidDate

public static boolean isValidDate(int year,
                                  int month,
                                  int day)
Test if the given values represent a valid date.


toString

public String toString()
Return a string representation of this date in the form yyyymmdd. This serves for debug purpose only. To get a locale dependent string use the DateFormat class.

See Also:
DateFormat

toCalendar

public Calendar toCalendar()
Convert the date to an Calendar.


toJavaDate

public Date toJavaDate()
Convert the date to an java.util.Date.


toJavaSqlDate

public Date toJavaSqlDate()
Convert the date to an java.sql.Date.


toInteger

public int toInteger()
Return an integer representation of this date.


toInteger

public static int toInteger(int day,
                            int month,
                            int year)
Return an integer representation of the given date values.


fromInteger

public static Date fromInteger(int value)
Extract a date from an integer.

See Also:
toInteger()

toJulianDayNumber

public int toJulianDayNumber()
Convert a date (more accurate: the noon of this date) to its Julian Day Number. The algorithm is described at http://www.capecod.net/~pbaum/date/date0.htm.


clone

public Object clone()
Clone this date.


hashCode

public int hashCode()
Get a hashcode for the date.