|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.emarsys.ecommon.time.Dates
public class Dates
Common utilities for handling dates.
Field Summary | |
---|---|
static int |
DAY_IN_MILLIS
|
static java.text.DateFormat |
FORMAT_TIMESTAMP
|
static int |
HOUR_IN_MILLIS
|
static int |
MINUTE_IN_MILLIS
|
static int |
SECOND_IN_MILLIS
|
static int |
WEEK_IN_MILLIS
|
Constructor Summary | |
---|---|
Dates()
|
Method Summary | |
---|---|
static java.util.Calendar |
add(java.util.Calendar cal,
int millis)
Creates a new Calendar instance by cloning the passed one
and adds the passed milliseconds to it. |
static java.util.Calendar |
add(java.util.Calendar cal,
int field,
int amount)
Creates a new Calendar instance by cloning the passed one
and adds the time specified through the passed field and amount. |
static java.lang.String |
format(java.util.Date date,
java.text.DateFormat fmt)
Formats the passed date with the passed DateFormat
and returns the String representation or null
iff the passed date is null . |
static java.lang.String |
format(java.util.Date date,
java.text.DateFormat fmt,
java.lang.String nullSurrogate)
Formats the passed date with the passed DateFormat
and returns the String representation or nullSurrogate
iff the passed date is null . |
static int |
getDayOfMonthCeil(java.util.Calendar cal,
int dayOfMonth)
correct day of month regarding maximum day of month, ceiling behavior. |
static java.util.Calendar |
getMean(java.util.Calendar start,
java.util.Calendar end)
The passed Calendar will be a clone of the first parameter. |
static int |
nbrOfDaysFromNowToDate(java.util.Date date)
|
static int |
nbrOfMonthsFromNowToDate(java.util.Date date)
|
static java.lang.String |
timestampToString(java.util.Calendar cal)
Formats, see format(Date, DateFormat) , the passed
Calendar with FORMAT_TIMESTAMP and returns the
String representation or null
iff the passed calendar is null . |
static java.lang.String |
timestampToString(java.util.Date date)
Formats, see format(Date, DateFormat) , the passed
Date with FORMAT_TIMESTAMP and returns the
String representation or null
iff the passed date is null . |
static java.util.Calendar |
toCalendar(java.util.Date date)
Converts the passed Date instance into a Calendar . |
static java.util.Calendar |
toCalendar(long timeMillis)
Creates a new Calendar with its time set to the passed
milliseconds. |
static java.util.Date |
valueOf(java.util.Calendar cal)
Converts the passed Calendar into Date instance. |
static java.util.Date |
valueOf(long timeMillis)
Creates a new Date instance with its time set to
the passed milliseconds. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SECOND_IN_MILLIS
public static final int MINUTE_IN_MILLIS
public static final int HOUR_IN_MILLIS
public static final int DAY_IN_MILLIS
public static final int WEEK_IN_MILLIS
public static final java.text.DateFormat FORMAT_TIMESTAMP
Constructor Detail |
---|
public Dates()
Method Detail |
---|
public static int nbrOfDaysFromNowToDate(java.util.Date date)
date
-
public static int nbrOfMonthsFromNowToDate(java.util.Date date)
date
-
public static int getDayOfMonthCeil(java.util.Calendar cal, int dayOfMonth)
cal
- - set to date within month where calculation shall be done.dayOfMonth
- - to correct.
public static java.lang.String format(java.util.Date date, java.text.DateFormat fmt, java.lang.String nullSurrogate)
DateFormat
and returns the String
representation or nullSurrogate
iff the passed date is null
.
date
- fmt
-
String
public static java.lang.String format(java.util.Date date, java.text.DateFormat fmt)
DateFormat
and returns the String
representation or null
iff the passed date is null
.
date
- fmt
-
String
or null
public static java.lang.String timestampToString(java.util.Date date)
format(Date, DateFormat)
, the passed
Date
with FORMAT_TIMESTAMP
and returns the
String
representation or null
iff the passed date is null
.
date
- - the timestamp to be formated
String
or null
.public static java.lang.String timestampToString(java.util.Calendar cal)
format(Date, DateFormat)
, the passed
Calendar
with FORMAT_TIMESTAMP
and returns the
String
representation or null
iff the passed calendar is null
.
date
- - the timestamp to be formated
String
or null
.public static java.util.Calendar toCalendar(java.util.Date date)
Date
instance into a Calendar
.
date
- - the Date
to be converted.
Date
converted into a new Calendar
instance with the default Locale
and TimeZone
,
if null
is passed null
will be returned.public static java.util.Calendar toCalendar(long timeMillis)
Calendar
with its time set to the passed
milliseconds.
timeMillis
-
Calendar
instance.public static java.util.Date valueOf(java.util.Calendar cal)
Calendar
into Date
instance.
cal
- - the Calendar
instance to be
converted to a Date
Date
returned by the passed instance's
Calendar.getTime()
method or null
if
the passed calendar is null
.public static java.util.Date valueOf(long timeMillis)
Date
instance with its time set to
the passed milliseconds.
timeMillis
-
Date
instance.public static java.util.Calendar getMean(java.util.Calendar start, java.util.Calendar end)
start
- end
-
Calendar
instance that has its time set
to the arithmetical mean of the passed dates.
java.lang.NullPointerException
- - if any of the passed dates is
null
.public static java.util.Calendar add(java.util.Calendar cal, int field, int amount)
Calendar
instance by cloning the passed one
and adds the time specified through the passed field and amount.
cal
- -field
- amount
-
Calendar
instance with its time
set to the passed ones and added the passed amount of time.public static java.util.Calendar add(java.util.Calendar cal, int millis)
Calendar
instance by cloning the passed one
and adds the passed milliseconds to it.
cal
- -field
- amount
-
Calendar
instance with its time
set to the passed ones and added the passed amount of time.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |