Class MyDate
-
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<Calendar>
public class MyDate extends GregorianCalendar
This class extends GregorianCalendar, mostly to provide methods that make dealing with dates (without time of day) more convenient. Of course you can look at the API documentation for Calendar to see what methods MyDate inherits from Calendar. Note: MyDate's interface on Calendar uses month numbers 1,2,...,12, while Calendar itself uses 0,1,...,11. Beware of this if you try to use methods from the Calendar class!- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.Calendar
Calendar.Builder
-
-
Field Summary
-
Fields inherited from class java.util.GregorianCalendar
AD, BC
-
Fields inherited from class java.util.Calendar
ALL_STYLES, AM, AM_PM, APRIL, areFieldsSet, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, fields, FRIDAY, HOUR, HOUR_OF_DAY, isSet, isTimeSet, JANUARY, JULY, JUNE, LONG, LONG_FORMAT, LONG_STANDALONE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NARROW_FORMAT, NARROW_STANDALONE, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SHORT, SHORT_FORMAT, SHORT_STANDALONE, SUNDAY, THURSDAY, time, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MyDateclone()Creates a new MyDate object identical to this.intdaysUntil(MyDate d)Returns the number of days (with sign) between MyDate d and this.intgetDay()Returns the year of this MyDate object.intgetMonth()Returns the month of this MyDate object.intgetYear()Returns the year of this MyDate object.voidincDay(int k)Adds k days to the current date.voidincMonth(int k)Adds k months to the current date.voidincYear(int k)Adds k years to the current date.static MyDatemakeDate(int y, int m, int d)Returns a new MyDate object initialized to thegiven year, month and day.StringtoString()Returns a String representation of this MyDate in the usual mm/dd/yyyy format.-
Methods inherited from class java.util.GregorianCalendar
add, computeFields, computeTime, equals, from, getActualMaximum, getActualMinimum, getCalendarType, getGreatestMinimum, getGregorianChange, getLeastMaximum, getMaximum, getMinimum, getTimeZone, getWeeksInWeekYear, getWeekYear, hashCode, isLeapYear, isWeekDateSupported, roll, roll, setGregorianChange, setTimeZone, setWeekDate, toZonedDateTime
-
Methods inherited from class java.util.Calendar
after, before, clear, clear, compareTo, complete, get, getAvailableCalendarTypes, getAvailableLocales, getDisplayName, getDisplayNames, getFirstDayOfWeek, getInstance, getInstance, getInstance, getInstance, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, internalGet, isLenient, isSet, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, toInstant
-
-
-
-
Method Detail
-
makeDate
public static MyDate makeDate(int y, int m, int d)
Returns a new MyDate object initialized to thegiven year, month and day. E.g.MyDate dt = makeDate(2015,1,17); // makes 17 January 2015.
-
getYear
public int getYear()
Returns the year of this MyDate object. E.g. 2015
-
getMonth
public int getMonth()
Returns the month of this MyDate object. Result is in [1,2,...,12]
-
getDay
public int getDay()
Returns the year of this MyDate object. Result is in [1,2,...,31]
-
incYear
public void incYear(int k)
Adds k years to the current date. This MyDate object is modified!
-
incMonth
public void incMonth(int k)
Adds k months to the current date. This MyDate object is modified!
-
incDay
public void incDay(int k)
Adds k days to the current date. This MyDate object is modified!
-
clone
public MyDate clone()
Creates a new MyDate object identical to this. This is important because the increment methods modify the MyDate object on which they are called. So for example, afterMyDate A = makeDate(2015,3,18); MyDate B = A; B.incDay(3);both A and B refer to the same MyDate object 3/21/2015. On the other hand, afterMyDate C = makeDate(2015,3,18); MyDate D = C.clone(); D.incDay(3);D refers to MyDate object 3/21/2015, while C refers to MyDate object 3/18/2015.- Overrides:
clonein classGregorianCalendar
-
toString
public String toString()
Returns a String representation of this MyDate in the usual mm/dd/yyyy format.
-
daysUntil
public int daysUntil(MyDate d)
Returns the number of days (with sign) between MyDate d and this. For exampleMyDate d1 = makeDate(2016,1,31); MyDate d2 = makeDate(2016,2,1); System.out.println(d1.daysUntil(d2));outputs 1.
-
-