prog.utils
Class MyDate

java.lang.Object
  |
  +--prog.utils.MyDate
All Implemented Interfaces:
java.lang.Comparable

public class MyDate
extends java.lang.Object
implements java.lang.Comparable

This wrapper class for Calendar provides various date-related utilities.


Field Summary
 java.util.Calendar calendar
          The Calendar wrapped in this instance of MyDate.
 java.lang.String date
          The date in "month day, year" form, such as Oct 23, 1982.
 java.lang.String day
          The 0-padded day number, such as 03, 20, and 07.
 int dayInt
          The numerical day of the month, such as 3.
 java.lang.String dayOfWeek
          The day of the week, such as Wed and Fri.
 java.lang.String month
          The month, such as Oct and Mar.
 int monthInt
          The numerical month of the year, such as 2.
 java.lang.String monthNum
          The 0-padded month number, such as 03, 10, and 11.
 java.lang.String priorYear
          The year before the year of this MyDate, such as 1985.
 java.lang.String time
          The military time, such as 15:34:23.
 java.lang.String timestamp
          The date in timestamp form, such as Sat Oct 20 17:32:52 PDT 2001.
 java.lang.String year
          The year, such as 1986.
 int yearInt
          The four-digit year number, such as 1987.
 java.lang.String yymmdd
          The date in yymmdd form, such as 010205 for 2001 Feb 5.
 java.lang.String yyyymmdd
          The date in yyyymmdd form, such as 20010205 for 2001 Feb 5.
 java.lang.String zone
          The timezone, such as PST.
 
Constructor Summary
MyDate()
          Initializes the Calendar of this object to today.
MyDate(java.util.Calendar cal)
          Initializes the Calendar of this object to cal.
 
Method Summary
 int compareTo(java.lang.Object ob2)
          Returns -1 if this MyDate is earlier in time than ob2, 0 if the same and 1 if later.
static MyDate daysAgo(int days)
          Returns a MyDate object that is 'days' number of days before today.
static void main(java.lang.String[] args)
           
 java.lang.String monthsAgo(int ago)
          Returns the 0-padded month number of the month that is 'ago' months before the month of this MyDate.
 java.lang.String toString()
          Prints the values of the variables of the MyDate instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

calendar

public java.util.Calendar calendar
The Calendar wrapped in this instance of MyDate.

timestamp

public java.lang.String timestamp
The date in timestamp form, such as Sat Oct 20 17:32:52 PDT 2001.

dayOfWeek

public java.lang.String dayOfWeek
The day of the week, such as Wed and Fri.

day

public java.lang.String day
The 0-padded day number, such as 03, 20, and 07.

month

public java.lang.String month
The month, such as Oct and Mar.

time

public java.lang.String time
The military time, such as 15:34:23.

zone

public java.lang.String zone
The timezone, such as PST.

year

public java.lang.String year
The year, such as 1986.

date

public java.lang.String date
The date in "month day, year" form, such as Oct 23, 1982.

monthNum

public java.lang.String monthNum
The 0-padded month number, such as 03, 10, and 11.

priorYear

public java.lang.String priorYear
The year before the year of this MyDate, such as 1985.

yymmdd

public java.lang.String yymmdd
The date in yymmdd form, such as 010205 for 2001 Feb 5.

yyyymmdd

public java.lang.String yyyymmdd
The date in yyyymmdd form, such as 20010205 for 2001 Feb 5.

dayInt

public int dayInt
The numerical day of the month, such as 3.

monthInt

public int monthInt
The numerical month of the year, such as 2.

yearInt

public int yearInt
The four-digit year number, such as 1987.
Constructor Detail

MyDate

public MyDate()
Initializes the Calendar of this object to today.

MyDate

public MyDate(java.util.Calendar cal)
Initializes the Calendar of this object to cal.
Method Detail

compareTo

public int compareTo(java.lang.Object ob2)
Returns -1 if this MyDate is earlier in time than ob2, 0 if the same and 1 if later.
Specified by:
compareTo in interface java.lang.Comparable

daysAgo

public static MyDate daysAgo(int days)
Returns a MyDate object that is 'days' number of days before today.

monthsAgo

public java.lang.String monthsAgo(int ago)
Returns the 0-padded month number of the month that is 'ago' months before the month of this MyDate. For example, if this MyDate's monthNum is 10, monthsAgo(3) is "07".

toString

public java.lang.String toString()
Prints the values of the variables of the MyDate instance. For example:
timestamp : Sat Oct 20 17:32:52 PDT 2001
dayOfWeek : Sat
day : 20
month : Oct
time : 17:32:52
zone : PDT
year : 2001
date : Oct 20, 2001
priorYear : 2000
dayInt : 20
monthInt : 10
yearInt : 2001
yymmdd : 011020
yyyymmdd : 20011020
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)