|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.perdues.StyleDate
The StyleDate class makes it convenient to combine Calendar and time arithmetic with formatting. Combines the functions of java.util.Date, java.sql.Date, SimpleDateFormat, and Calendar with a single interface.
A StyleDate maintains a current date/time, and provides methods to set the various date/time fields and to add (or subtract) from its current value. The toString method formats the current date/time according to the current format.
You can set the day within the current week, the day of the month, the month, or the year directly, and set the time to the beginning of the day. You can add positive or negative numbers of days, months, years, or milliseconds to the internal date/time with calendar-based results.
All the calendar fields are available with normalized data at all times. For example, if you set the date/time to the beginning of the month, then add a month, the date/time is the beginning of the next month.
The TimeZone and Locale are configurable as well as the format.
Constructor Summary | |
StyleDate()
Creates a StyleDate with the current date and time. |
|
StyleDate(java.util.Date d)
Creates a StyleDate for the given Date. |
|
StyleDate(java.util.Date d,
java.lang.String fmt)
Create a StyleDate with a particular format and Date. |
|
StyleDate(long millis)
Creates a StyleDate for the given absolute time in milliseconds. |
|
StyleDate(java.lang.String fmt)
Creates a StyleDate with the current date/time and the given format, which it localizes. |
|
StyleDate(StyleDate s)
Creates a StyleDate with the same date/time, format, locale, and timezone as the one given. |
Method Summary | |
void |
addDays(int n)
Ajust the day forward the given number of days, negative to go back. |
void |
addMillis(long m)
|
void |
addMonths(int n)
Ajust the month forward the given number of months, negative to go back. |
void |
addYears(int n)
Ajust the year forward the given number of years, negative to go back. |
boolean |
after(java.util.Date d)
Is this date after the argument? |
boolean |
after(StyleDate d)
Is this date after the argument? |
java.util.Date |
asDate()
Return the current date/time as a Date. |
long |
asMillis()
Returns the current date/time in milliseconds. |
boolean |
before(java.util.Date d)
Is this date before the argument? |
boolean |
before(StyleDate d)
Is this date before the argument? |
java.lang.String |
format()
Format the currently-set date/time. |
int |
get(int field)
Gets an arbitrary Calendar field. |
int |
getFirstDayOfWeek()
Returns the first day of the week for the locale. |
static void |
main(java.lang.String[] args)
|
void |
set(int field,
int value)
Sets an arbitrary Calendar field. |
void |
setDate(java.util.Date d)
Sets the date/time to the given Date. |
void |
setDate(java.lang.String date)
Sets the date/time to the formatted date, parsing leniently according to the current format. |
void |
setDay(int d)
Sets the day of the month. |
void |
setDayOfWeek(int d)
Sets the day of the week to the given constant within the current week, where the current week is determined by the locale's notion of "first day" of a week. |
void |
setFormat(java.lang.String fmt)
Sets the format (does not localize it, whatever that implies). |
void |
setLocale(java.util.Locale loc)
|
void |
setLocalizedFormat(java.lang.String fmt)
Sets the format, translating it to a localized version. |
void |
setMillis(long m)
Sets the date/time to an absolute value in milliseconds. |
void |
setMonth(int m)
Sets the month, zero-based counting. |
void |
setTimeZone(java.util.TimeZone z)
|
void |
setToStartOfDay()
Sets the date/time to the beginning of the day, local time. |
void |
setYear(int y)
Sets the year. |
java.lang.String |
sqlFormat()
Format the currently-set date/time for SQL. |
java.lang.String |
toString()
Formats the currently-set date/time. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public StyleDate()
public StyleDate(java.util.Date d)
public StyleDate(long millis)
public StyleDate(java.lang.String fmt)
public StyleDate(StyleDate s)
public StyleDate(java.util.Date d, java.lang.String fmt)
Method Detail |
public void setDate(java.util.Date d)
public void setDate(java.lang.String date) throws java.text.ParseException
public void setMillis(long m)
public void setFormat(java.lang.String fmt)
public void setLocalizedFormat(java.lang.String fmt)
public void setTimeZone(java.util.TimeZone z)
public void setLocale(java.util.Locale loc)
public java.util.Date asDate()
public long asMillis()
public java.lang.String sqlFormat()
public java.lang.String format()
public java.lang.String toString()
toString
in class java.lang.Object
public void setDay(int d)
public int getFirstDayOfWeek()
public void setDayOfWeek(int d)
public void setToStartOfDay()
public void setMonth(int m)
public void setYear(int y)
public void addDays(int n)
public void addMonths(int n)
public void addYears(int n)
public void addMillis(long m)
public int get(int field)
public void set(int field, int value)
public boolean after(java.util.Date d)
public boolean after(StyleDate d)
public boolean before(java.util.Date d)
public boolean before(StyleDate d)
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |