|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object becker.util.DateTime
public class DateTime
A class to represent an instant in time that is simpler to use than either Date or GregorianCalendar.
Field Summary | |
---|---|
static int |
DATE_AND_TIME
Cause format(...) to return the date and time. |
static int |
DATE_ONLY
Cause format(...) to return the date only. |
static int |
LONG
Cause format(...) to use a long format. |
static int |
MEDIUM
Cause format(...) to use a medium-length format. |
static int |
SHORT
Cause format(...) to use a short format. |
static int |
TIME_ONLY
Cause format(...) to return the time only. |
Constructor Summary | |
---|---|
DateTime()
Construct a new date object representing the current instant in time. |
|
DateTime(DateTime dt)
Construct a new DateTime object that represents the same date as dt . |
|
DateTime(int year,
int month,
int day)
Construct a new date object representing the given year, month, and day. |
|
DateTime(int year,
int month,
int day,
int hours,
int minutes,
int seconds)
Construct a new date object representing the given year, month, and day. |
|
DateTime(Scanner in)
Read a date from in , leaving the file cursor immediately
after the date. |
Method Summary | |
---|---|
void |
addDays(int howMany)
Add (or subtract, if negative) days from this DateTime. |
void |
addHours(int howMany)
Add (or subtract, if negative) hours from this DateTime. |
void |
addMinutes(int howMany)
Add (or subtract, if negative) minutes from this DateTime. |
void |
addMonths(int howMany)
Add (or subtract, if negative) months from this DateTime. |
void |
addSeconds(int howMany)
Add (or subtract, if negative) seconds from this DateTime. |
void |
addYears(int howMany)
Add (or subtract, if negative) years from this DateTime. |
Object |
clone()
Clone this Date/Time object to produce another one, just like it. |
int |
compareTo(Object dt)
Compare two DateTime objects. |
int |
daysUntil(DateTime another)
Calculate the number of days until another date. |
boolean |
equals(Object other)
Determine whether this Date/Time is equal to another. |
String |
format()
Format the date and/or time as a string according to the current settings established by setFormatInclude
and setFormatLength . |
int |
getDay()
Get the day. |
int |
getHour()
Get the hour. |
int |
getMinute()
Get the minute. |
int |
getMonth()
Get the month. |
static DateTime |
getNowInstance()
Get an instance representing the current date and time. |
int |
getSecond()
Get the second. |
Date |
getTime()
Return an object that can be passed to an instance of DateFormat. |
static DateTime |
getTodayInstance()
Get an instance representing today (time fields set to midnight). |
int |
getYear()
Get the year. |
int |
hashCode()
Returns a hash code for this object for use in HashSet and
related collections. |
boolean |
isAfter(DateTime other)
Determine whether this Date/Time is after another. |
boolean |
isBefore(DateTime other)
Determine whether this Date/Time is before another. |
void |
setDay(int day)
Set the day for this to the given day |
void |
setFormatInclude(int formatInclude)
Set the data to include in the string returned by format(). |
void |
setFormatLength(int formatLength)
Set the length of the string returned by format(). |
void |
setHour(int hour)
Set the hour for this to the given hour |
void |
setMinute(int minute)
Set the minute for this to the given minute |
void |
setMonth(int month)
Set the month for this to the given month |
void |
setSecond(int second)
Set the second for this to the given second |
void |
setTime(int hour,
int min,
int sec)
Set the time for this to the given hour, minute and second. |
void |
setYear(int year)
Set the year for this to the given year |
String |
toString()
Represent this date (and time, if the time is not midnight) as a string. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int SHORT
public static final int MEDIUM
public static final int LONG
public static final int DATE_ONLY
public static final int TIME_ONLY
public static final int DATE_AND_TIME
Constructor Detail |
---|
public DateTime()
public DateTime(int year, int month, int day)
year
- The year {e.g. 2003}month
- The month in the range 1..12day
- The day in the range 1..31public DateTime(int year, int month, int day, int hours, int minutes, int seconds)
year
- The year {e.g. 2003}month
- The month in the range 1..12day
- The day in the range 1..31hours
- The hour in the range 0..23minutes
- The minutes in the range 0..59seconds
- The seconds in the range 0..59public DateTime(Scanner in)
in
, leaving the file cursor immediately
after the date. The date (and optional time) must be in one of the
two formats produced by toString
.
in
- The open file from which to read the date.public DateTime(DateTime dt)
dt
.
dt
- The DateTime object to duplicate.Method Detail |
---|
public static DateTime getTodayInstance()
public static DateTime getNowInstance()
public int compareTo(Object dt)
compareTo
in interface Comparable
dt
- A DateTime object to compare to this object. It must be a DateTime
object in spite of the fact that the parameter has type Object.
public void setFormatLength(int formatLength)
formatLength
- One of DateTime.{SHORT, MEDIUM, LONG}public void setFormatInclude(int formatInclude)
formatInclude
- One of DateTime.{DATE_ONLY, TIME_ONLY, DATE_AND_TIME}public String format()
setFormatInclude
and setFormatLength
.
Examples:
Length Include Format SHORT DATE_AND_TIME 3/27/08 1:15 PM SHORT DATE_ONLY 3/27/08 SHORT TIME_ONLY 1:15 PM MEDIUM DATE_AND_TIME Mar 27, 2008 1:15:15 PM MEDIUM DATE_ONLY Mar 27, 2008 MEDIUM TIME_ONLY 1:15:15 PM LONG DATE_AND_TIME March 27, 2008 1:15:15 PM EST LONG DATE_ONLY March 27, 2008 LONG TIME_ONLY 1:15:15 PM EST
public String toString()
toString
in class Object
public int getYear()
public int getMonth()
public int getDay()
public int getHour()
public int getMinute()
public int getSecond()
public void addYears(int howMany)
howMany
- The number of years to add or subtract.public void addMonths(int howMany)
howMany
- The number of months to add or subtract.public void addDays(int howMany)
howMany
- The number of days to add or subtract.public void addHours(int howMany)
howMany
- The number of hours to add or subtract.public void addMinutes(int howMany)
howMany
- The number of minutes to add or subtract.public void addSeconds(int howMany)
howMany
- The number of seconds to add or subtract.public void setYear(int year)
year
- the new year for thispublic void setMonth(int month)
month
- the new month for thispublic void setDay(int day)
day
- the new day for thispublic void setHour(int hour)
hour
- the new hour for thispublic void setMinute(int minute)
minute
- the new minute for thispublic void setSecond(int second)
second
- the new second for thispublic void setTime(int hour, int min, int sec)
hour
- The new hourmin
- The new minutesec
- The new secondpublic boolean isBefore(DateTime other)
other
- The other DateTime to compare against
other
.public boolean isAfter(DateTime other)
other
- The other DateTime to compare against
other
.public boolean equals(Object other)
equals
in class Object
other
- The other DateTime to compare against
other
public Object clone()
clone
in class Object
public int hashCode()
HashSet
and
related collections.
hashCode
in class Object
public int daysUntil(DateTime another)
another
, the result will be positive. If
this date is after another
, the result will be negative.
another
- A DateTime object.
public Date getTime()
DateTime today = new DateTime(); DateFormat df = DateFormat.getDateInstance(); df.format(today.getTime());
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |