|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jcoderz.commons.types.Date
public final class Date
Immutable holder of a Date running through our system. This class also holds some time related constants to be used in the code. Years before 1 are not fully supported and might result in wrong string representations.
| Field Summary | |
|---|---|
static String |
DATE_FORMAT
The format used to parse and write schema date types. |
static String |
DATE_TIME_FORMAT
The format used to write schema dateTime types. |
static ThreadLocal |
DATE_TIME_FORMAT_FORMATER
Date Formater to use for DATE_TIME_FORMAT format. |
static String |
DATE_TIME_FORMAT_WITH_MILLIS
The format used to write schema dateTime types, if milli seconds are not equal 0. |
static ThreadLocal |
DATE_TIME_FORMAT_WITH_MILLIS_FORMATER
Date Formater to use for DATE_TIME_FORMAT_WITH_MILLIS format. |
static Date |
FUTURE_DATE
This date represents the largest possible date (9999 * 365 * 24 * 60 * 60 * 1000). |
static int |
MILLIS_PER_DAY
Number of milliseconds per day. |
static int |
MILLIS_PER_HOUR
Number of milli seconds in an hour. |
static int |
MILLIS_PER_MINUTE
Number of milli seconds in a minute. |
static int |
MILLIS_PER_SECOND
Number of milli seconds in a second. |
static int |
MILLIS_PER_WEEK
Number of milliseconds per week. |
static int |
MONTH_PER_YEAR
Number of months per year. |
static long |
NANOS_PER_MILLI
Number of nano seconds in a milli second. |
static long |
NANOS_PER_SECOND
Number of nano seconds in a second. |
static Date |
OLD_DATE
This date represents the 1.1.1970 00:00:00.000. |
static int |
SECONDS_PER_MINUTE
Number of seconds in a minute. |
static TimeZone |
TIME_ZONE
Timezone used by the protocol. |
static String |
TYPE_NAME
The name of this type. |
| Constructor Summary | |
|---|---|
Date(long time)
Creates a new instance of Date taking the given long as ms from 1.1.1970. |
|
| Method Summary | |
|---|---|
boolean |
after(Date other)
Checks if this date is after the given date. |
boolean |
afterOrEqual(Date other)
Checks if this date is after or equal to the given date. |
boolean |
before(Date other)
Checks if the this date is before the given date. |
boolean |
beforeOrEqual(Date other)
Checks if the this date is before or equal to the given date. |
int |
compareTo(Object o)
Compares this Date to another Object. |
static Date |
earliest(Date a,
Date b)
Returns the earliest of the two dates. |
long |
elapsedMillis()
Returns the elapsed number of milliseconds from this date to now. |
long |
elapsedMillis(Date other)
Returns the elapsed number of milliseconds from this date to other. |
boolean |
equals(Object obj)
Compares two dates for equality. |
static Date |
fromLong(long time)
Creates a new instance of Date taking the given long as ms from 1.1.1970. |
static Date |
fromSqlDate(Date date)
Creates a new instance of Date holding the value as found in the given java.sql.Date. |
static Date |
fromSqlTimestamp(Timestamp timestamp)
Creates a new instance of Date holding the value as found in the given java.sql.Timestamp. |
static Date |
fromString(String date)
Parses the given String as returned by the toString method. |
static Date |
fromString(String date,
String pattern)
Parses the given String with the given format pattern. |
static Date |
fromUtilDate(Date date)
Creates a new instance of Date from a java.util.Date Object. |
static int |
getDaysSinceEpoch()
Returns the number of days since the Unix Epoch (1970/01/01). |
static int |
getDaysSinceEpoch(Date d)
Returns the number of days between Unix Epoch (1970/01/01) and d. |
long |
getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. |
int |
hashCode()
Returns a hash code value for this object. |
static Date |
latest(Date a,
Date b)
Returns the latest of the two dates. |
Date |
minus(long offset)
Returns a Date object that holds the time of this object minus the given milliseconds in the past. |
static Date |
now()
Returns a Date object that holds the current time. |
static Date |
nowPlus(long offset)
Returns a Date object that holds the current time plus the given milliseconds in the future. |
Date |
plus(long offset)
Returns a Date object that holds the time of this object plus the given milliseconds in the future. |
String |
toDateString()
Returns the String representation format is according schema date representation. |
Date |
toSqlDate()
Returns the date represented by this object as newly generated java.sql.Date object. |
Timestamp |
toSqlTimestamp()
Returns the date represented by this object as newly generated java.sql.Timestamp object. |
String |
toString()
Returns the String representation format is according schema dateTime representation. |
String |
toString(String pattern)
Returns the date as formatted string using the given pattern. |
Date |
toUtilDate()
Returns the date represented by this object as newly generated java.util.Date object. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final ThreadLocal DATE_TIME_FORMAT_WITH_MILLIS_FORMATER
public static final ThreadLocal DATE_TIME_FORMAT_FORMATER
public static final String TYPE_NAME
public static final TimeZone TIME_ZONE
public static final long NANOS_PER_MILLI
public static final int MILLIS_PER_SECOND
public static final long NANOS_PER_SECOND
public static final int SECONDS_PER_MINUTE
public static final int MILLIS_PER_MINUTE
public static final int MILLIS_PER_HOUR
public static final int MILLIS_PER_DAY
public static final int MILLIS_PER_WEEK
public static final int MONTH_PER_YEAR
public static final Date OLD_DATE
public static final Date FUTURE_DATE
public static final String DATE_TIME_FORMAT
public static final String DATE_TIME_FORMAT_WITH_MILLIS
public static final String DATE_FORMAT
| Constructor Detail |
|---|
public Date(long time)
time - the number of milliseconds.| Method Detail |
|---|
public static Date fromLong(long time)
time - the number of milliseconds.
Date.Date()public static Date fromUtilDate(Date date)
date - the date as java.util.Date.
public static Date fromSqlDate(Date date)
date - the date as java.sql.Date.
public static Date fromSqlTimestamp(Timestamp timestamp)
timestamp - the date as
java.sql.Timestamp.
public static Date fromString(String date,
String pattern)
throws ParseException
date - the date in given notationpattern - the pattern to be used for parsing.
ParseException - if the given date is not in the format of the
given pattern.SimpleDateFormat
public static Date fromString(String date)
throws ParseException
date - the date in String representation
ParseException - if the given date is not in the format of the
Date.toString() format.public static Date now()
public static Date nowPlus(long offset)
offset - the number of millis to step into the future.
public static int getDaysSinceEpoch()
public static int getDaysSinceEpoch(Date d)
d.
d - the date until when the number of days should be computed
d.
public static Date earliest(Date a,
Date b)
a - date a to compare.b - date b to compare.
public static Date latest(Date a,
Date b)
a - date a to compare.b - date b to compare.
public Date plus(long offset)
offset - the number of millis to step into the future.
public Date minus(long offset)
offset - the number of millis to step back from this date.
public Date toUtilDate()
java.util.Date object.
java.util.Date object.public Date toSqlDate()
java.sql.Date object.
java.sql.Date object.public Timestamp toSqlTimestamp()
java.sql.Timestamp object.
java.sql.Timestamp object.public int hashCode()
getTime()
method. That is, the hash code is the value of the expression:
(int)(this.getTime()^(this.getTime() >>> 32))
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectobj - the object to compare with.
true if the objects are the same;
false otherwise.public String toString(String pattern)
pattern - the pattern describing the date and time format
SimpleDateFormatpublic String toString()
toString in class Objectpublic String toDateString()
public long getTime()
public int compareTo(Object o)
throws NullPointerException,
ClassCastException
compareTo in interface Comparableo - the Object to be compared.
0 if the argument is a Date
equal to this Date; a value less than 0 if the
argument is a Date after this Date; and a value greater than
0 if the argument is a Date before this Date.
ClassCastException - if the argument is not a
org.jcoderz.ipp.Date.
NullPointerException - if the argument is null.Comparablepublic boolean before(Date other)
other - the date to compare with.
public boolean beforeOrEqual(Date other)
other - the date to compare with.
public boolean after(Date other)
other - the date to compare with.
public boolean afterOrEqual(Date other)
other - the date to compare with.
public long elapsedMillis()
public long elapsedMillis(Date other)
other - the date to compare with this date.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||