public class Date extends java.lang.Object implements Comparable
Modifier and Type | Field and Description |
---|---|
static int |
APRIL |
static int |
AUGUST |
static boolean |
BACKWARD
Used in the advance methods.
|
static int |
DECEMBER |
static int |
FEBRUARY |
static boolean |
FORWARD
Used in the advance methods.
|
static int |
JANUARY |
static int |
JULY |
static int |
JUNE |
static int |
MARCH |
static int |
MAY |
static int |
minValidYear
Defines the minimum valid year.
|
static java.lang.String[] |
monthNames
The month names used in some routines.
|
static int |
NOVEMBER |
static int |
OCTOBER |
static int |
SEPTEMBER |
static Date |
SQL_EPOCH |
Constructor and Description |
---|
Date()
Constructs a Date object set to the current date.
|
Date(int sentDate)
Constructs a Date object set to the passed int in the YYYYMMDD format
|
Date(int sentDay,
int sentMonth,
int sentYear)
Constructs a Date object set to the passed day, month, and year.
|
Date(java.lang.String strDate)
Constructs a Date object set to a passed string in the format specified in the current date format.
|
Date(java.lang.String strDate,
byte dateFormat)
Constructs a Date object set to a passed string in the format specified in the dateFormat parameter.
|
Date(Time t)
Constructs a new Date object with the values from the given Time object
|
Modifier and Type | Method and Description |
---|---|
void |
advance(int numberDays)
Advances the date by a passed integer.
|
void |
advanceMonth()
Advances the date to the beginning of the next month.
|
void |
advanceMonth(boolean direction)
Advances the date to the beginning of the next or previous month.
|
void |
advanceWeek()
Advances the date to the beginning of the next week.
|
void |
advanceWeek(boolean direction)
Advances the date to the beginning of the next or previous week.
|
int |
compareTo(java.lang.Object other)
Implementation of the Comparable interface.
|
boolean |
equals(java.lang.Object sentDate)
Checks to see if the Date object passed occurs at the same time as the existing Date object.
|
static java.lang.String |
formatDate(int day,
int month,
int year)
Formats the date specified with the Settings.dateFormat, zero padded.
|
static java.lang.String |
formatDate(int day,
int month,
int year,
byte dateFormat)
Formats the date specified with the dateFormat parameter, zero padded.
|
static java.lang.String |
formatDate(int day,
int month,
int year,
byte dateFormat,
java.lang.String dateSeparator)
Formats the date specified with the dateFormat parameter, zero padded, and using the given separator.
|
static java.lang.String |
formatDate(int day,
int month,
int year,
java.lang.String separator)
Formats the date specified with the Settings.dateFormat, zero padded, and using the given separator.
|
java.lang.String |
formatDayMonth()
Formats the day/month specified with the Settings.dateFormat, zero padded.
|
java.lang.String |
getDate()
Deprecated.
use toString()
|
int |
getDateInt()
Returns the date in a integer format.
|
int |
getDay()
Returns the day.
|
int |
getDayOfWeek()
Returns the day of week, where 0 is sunday and 6 is saturday.
|
int |
getDaysInMonth()
Returns number of days in the set month.
|
int |
getDaysInMonth(int month)
Returns number of days in the passed month of the current date's year.
|
static int |
getDaysInMonth(int month,
int year)
Returns number of days in the passed month and year.
|
int |
getGregorianDay()
Returns the number of days since the January 1 of the epoch year (1000).
|
int |
getMonth()
Returns the month.
|
static java.lang.String |
getMonthName(int m)
Returns the string representation of the month passed
|
long |
getSQLLong()
Returns this date in the Time.getTimeLong format, with hour/minute/second/millis equal to 0.
|
java.lang.String |
getSQLString()
Returns this date in the format
YYYY-MM-DD 00:00:00.000 |
java.lang.String |
getSQLString(java.lang.StringBuffer sb)
Returns this date in the format
YYYY-MM-DD 00:00:00.000 |
long |
getTime()
Returns the number of seconds since SQL_EPOCH 1/1/1970.
|
int |
getWeek()
Calculates and returns the ordinal value of the week(1-52).
|
int |
getYear()
Returns the year.
|
boolean |
isAfter(Date sentDate)
Checks to see if the Date object passed occurs after the existing Date object.
|
boolean |
isBefore(Date sentDate)
Checks to see if the Date object passed occurs before the existing Date object.
|
static boolean |
isLeapYear(int year)
Checks if the year is a leap year
|
int |
set(int day,
int month,
int year)
Sets the date fields to the given ones.
|
int |
set(java.lang.String strDate,
byte dateFormat)
Sets the date fields by parsing the given String, and using the dateFormat.
|
void |
setToday()
Sets this date object to be the current day
|
int |
subtract(Date other)
Returns the difference in days from this date and the given one (other - this).
|
java.lang.String |
toString()
Returns the date in a string format.
|
java.lang.String |
toString(byte format)
Returns the date as a string, in the given format.
|
java.lang.String |
toString(byte dateFormat,
java.lang.String separator)
Returns the date in a string format and using the given format and separator.
|
public static java.lang.String[] monthNames
public static int minValidYear
public static final int JANUARY
public static final int FEBRUARY
public static final int MARCH
public static final int APRIL
public static final int MAY
public static final int JUNE
public static final int JULY
public static final int AUGUST
public static final int SEPTEMBER
public static final int OCTOBER
public static final int NOVEMBER
public static final int DECEMBER
public static final boolean FORWARD
public static final boolean BACKWARD
public static Date SQL_EPOCH
public Date()
public Date(Time t) throws InvalidDateException
InvalidDateException
public Date(java.lang.String strDate, byte dateFormat) throws InvalidDateException
strDate
- string that should have the format specified in the Settings.dateFormat. Note: does not have to be separated by
the '-' character it can be separated by any non-number.dateFormat
- one of the Settings.DATE_ values.InvalidDateException
Settings.DATE_DMY
,
Settings.DATE_MDY
,
Settings.DATE_YMD
public Date(java.lang.String strDate) throws InvalidDateException
strDate
- string that should have the format specified in the Settings.dateFormat. Note: does not have to be separated by
the '-' character it can be separated by any non-number.InvalidDateException
Settings.dateFormat
public Date(int sentDate) throws InvalidDateException
sentDate
- an integer in the YYYYMMDD formatInvalidDateException
public Date(int sentDay, int sentMonth, int sentYear) throws InvalidDateException
sentDay
- - an integer that must be between 1 and the last day in the month.sentMonth
- - an integer that must be between 1 and 12.sentYear
- - an integer that must be between 1000 and 2999.InvalidDateException
public int set(int day, int month, int year) throws InvalidDateException
InvalidDateException
public int set(java.lang.String strDate, byte dateFormat) throws InvalidDateException
Settings.dateFormat
.
Trailing spaces are skipped.InvalidDateException
public void setToday()
public int getDayOfWeek()
public int getDay()
public int getMonth()
public int getYear()
public int getWeek()
public java.lang.String formatDayMonth()
public static java.lang.String formatDate(int day, int month, int year, byte dateFormat, java.lang.String dateSeparator)
Settings.DATE_DMY
,
Settings.DATE_MDY
,
Settings.DATE_YMD
public static java.lang.String formatDate(int day, int month, int year, java.lang.String separator)
public static java.lang.String formatDate(int day, int month, int year, byte dateFormat)
Settings.DATE_DMY
,
Settings.DATE_MDY
,
Settings.DATE_YMD
public static java.lang.String formatDate(int day, int month, int year)
@Deprecated public java.lang.String getDate()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(byte dateFormat, java.lang.String separator)
public java.lang.String toString(byte format)
Settings.DATE_DMY
,
Settings.DATE_MDY
,
Settings.DATE_YMD
public int getDateInt()
public int getDaysInMonth()
public int getDaysInMonth(int month)
month
- integer between 1 and 12.public static int getDaysInMonth(int month, int year)
month
- integer between 1 and 12.year
- integer with the year.public static java.lang.String getMonthName(int m)
m
- integer between 1 and 12.public boolean isBefore(Date sentDate)
sentDate
- object to compare with existing.public boolean isAfter(Date sentDate)
sentDate
- object to compare with existing.public boolean equals(java.lang.Object sentDate)
equals
in class java.lang.Object
sentDate
- object to compare with existing.public void advanceWeek()
public void advanceWeek(boolean direction)
direction
- - static variables FORWARD or BACKWARD instructs the method to either move to the next
or previous weekpublic void advanceMonth()
public void advanceMonth(boolean direction)
direction
- - static variables FORWARD or BACKWARD instructs the method to either move to the next
or previous monthpublic void advance(int numberDays)
numberDays
- integer containing number of days that the date should change can be positive or negativepublic int getGregorianDay()
public int subtract(Date other)
public static boolean isLeapYear(int year)
year
- year to be checkedpublic int compareTo(java.lang.Object other)
compareTo
in interface Comparable
public java.lang.String getSQLString(java.lang.StringBuffer sb)
YYYY-MM-DD 00:00:00.000
public java.lang.String getSQLString()
YYYY-MM-DD 00:00:00.000
public long getSQLLong()
public long getTime()