Date
Class Date

java.lang.Object
  extended by Date.Date

public class Date
extends java.lang.Object

A class to implement dates on the Gregorian calendar, i.e. any date since October 15, 1582. Date objects have a month, day, and year


Constructor Summary
Date(int month, int day, int year)
          Creates a date object
 
Method Summary
 void add(int days)
          Adds a specified number of days to a Date
 boolean equals(java.lang.Object otherDate)
          Are two Date objects equal? I.e.
 int getDay()
          Returns the day portion of a Date, as an int
 java.lang.String getDayOfWeek()
          Returns the day of the week (e.g.
 java.lang.String getLongDate()
          Returns the Date in long format, with day-of-week, month name, and the ordinal of the day
 java.lang.String getMediumDate()
          Returns the Date in medium format - with month name
 int getMonth()
          Returns the month as an int between 1 and 12
 java.lang.String getMonthName()
          Returns the month as a String (e.g.
 java.lang.String getShortDate()
          Returns the Date in short format - numbers only
 int getYear()
          Returns the year as a 4-digit int
 void next()
          Increases a Date by one day.
 void previous()
          Decreases a Date by one day.
 void subtract(int days)
          Subtracts a specified number of days from a Date
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Date

public Date(int month,
            int day,
            int year)
Creates a date object

Parameters:
month - the month
day - the day
year - the year
Throws:
Date.DateException - on attempt to create invalid date
Method Detail

getDay

public int getDay()
Returns the day portion of a Date, as an int

Returns:
the day

getMonth

public int getMonth()
Returns the month as an int between 1 and 12

Returns:
the month

getYear

public int getYear()
Returns the year as a 4-digit int

Returns:
the year

getMonthName

public java.lang.String getMonthName()
Returns the month as a String (e.g. "March")

Returns:
the name of the month

getDayOfWeek

public java.lang.String getDayOfWeek()
Returns the day of the week (e.g. "Saturday")

Returns:
the day of the week

equals

public boolean equals(java.lang.Object otherDate)
Are two Date objects equal? I.e. do they have the same day, month, and year?

Overrides:
equals in class java.lang.Object
Returns:
true if two dates are equal, false if not

next

public void next()
Increases a Date by one day. Month and year roll over as necessary. Example: Date d1 = new Date(12,31,2010) ; // December 31, 2010 d1.next() ; // d1 is now 1/1/2011


previous

public void previous()
Decreases a Date by one day. Month and year roll back as necessary. Ex: Date d1 = new Date(3,1,2012) ; // March 1, 2012 (a leap year) d1.previous ; // d1 is now 2/29/2012


add

public void add(int days)
Adds a specified number of days to a Date

Parameters:
days - the number of days by which to increase the Date (if negative, Date is decreased by that number)

subtract

public void subtract(int days)
Subtracts a specified number of days from a Date

Parameters:
days - the number of days by which to decrease the Date (if negative, Date is increased by that number)

getShortDate

public java.lang.String getShortDate()
Returns the Date in short format - numbers only

Returns:
the Date as "mm/dd/yyyy"

getMediumDate

public java.lang.String getMediumDate()
Returns the Date in medium format - with month name

Returns:
the Date as "month day, year" (E.g. October 15, 1582)

getLongDate

public java.lang.String getLongDate()
Returns the Date in long format, with day-of-week, month name, and the ordinal of the day

Returns:
the Date as "day-of-week, month day, year" (E.g. "Friday, October 15th, 1582")