public class Dates extends Object
| Constructor and Description |
|---|
Dates() |
| Modifier and Type | Method and Description |
|---|---|
static Date |
add(Date when,
TimeZone tz,
int field,
int amount)
Date Arithmetic function.
|
static Date |
beginOfDate(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the beginning date of
the specified date and TimeZone.
|
static Date |
beginOfMonth()
Return the beginning date of this month.
|
static Date |
beginOfMonth(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the beginning date of the
month of the specified date and TimeZone.
|
static Date |
beginOfYear()
Return the beginning date of this year.
|
static Date |
beginOfYear(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the beginning date of the
month of the specified date and TimeZone.
|
static int |
dayMonthOfDate(Date when,
TimeZone tz)
Get the day of month of a date.
|
static Date |
endOfDate(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the last millisecond date of
the specified date and TimeZone.
|
static Date |
endOfMonth()
Return the ending date of this month.
|
static Date |
endOfMonth(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the ending date of the
month of the specified date and TimeZone.
|
static Date |
endOfYear()
Return the ending date of this year.
|
static Date |
endOfYear(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the ending date of the
month of the specified date and TimeZone.
|
static long |
getTimezoneOffset(TimeZone timezone,
Date date)
Returns the timezone offset.
|
static boolean |
isBeginOfMonth(Date when,
TimeZone tz)
Whether the given date in the specified TimeZone is the first day of that
month.
|
static boolean |
isEndOfMonth(Date when,
TimeZone tz)
Whether the given date in the specified TimeZone is the last day of that
month.
|
static boolean |
isRounded(Date date,
int precision)
Tests whether a date is rounded.
|
static int |
localizedYearOfDate(Date when,
Locale locale,
TimeZone tz)
Get the year of a date in the specified locale.
|
static Date |
merge(Date datePart,
Date timePart,
TimeZone tz)
merge the date part and time part of two specified dates into a date.
|
static int |
monthOfDate(Date when,
TimeZone tz)
Get the month of a date.
|
static int |
monthOfDatePlus1(Date when,
TimeZone tz)
Get the month of a date.
|
static Date |
now()
Returns the current time without rounding.
|
static Date |
now(int precision)
Returns the current time but rounding to the specified precision
of milliseconds.
|
static Date |
previousDate(Date when)
Given a date, return the previous date of the given date (24 hrs before).
|
static Date |
round(Date date,
int precision)
Truncates date to the nearest precision milliseconds.
|
static long |
round(long time,
int precision)
Rounds a date represented in long to the specified precision of
milliseconds.
|
static long |
subtract(Date date2,
TimeZone tz,
int field,
Date date1)
Date Arithmetic function (date2 - date1).
|
static Date |
today()
Returns today by setting time to 0:0:0.
|
static short |
twoMonthShort()
Return the ending date of this year.
|
static short |
twoMonthShort(Date when,
TimeZone tz)
Given a date, a proper TimeZone, return the two month int.
|
static int |
yearOfDate(Date when,
TimeZone tz)
Get the year of a date.
|
public static final Date round(Date date, int precision)
now(int) for details.precision - the divider of the precision(e.g. 10 for precision
of 10 milliseconds;i.e. all millisecond less than 10 would be truncated)now(int),
round(long, int)public static final long round(long time,
int precision)
time - the date represented in long.precision - the divider of the precision(e.g. 10 for precision
of 10 milliseconds;i.e. all millisecond less than 10 would be truncated)now(int),
round(Date, int)public static final boolean isRounded(Date date, int precision)
public static final Date now(int precision)
If you don't cache it in the memory (remember entity beans always cache by the container), you don't need to round. If you are not sure, round it.
round(Date, int)public static final Date now()
public static final Date today()
public static final Date previousDate(Date when)
public static final Date beginOfMonth()
public static final Date beginOfMonth(Date when, TimeZone tz)
public static final Date endOfMonth()
public static final Date endOfMonth(Date when, TimeZone tz)
public static final boolean isEndOfMonth(Date when, TimeZone tz)
public static final boolean isBeginOfMonth(Date when, TimeZone tz)
public static final Date beginOfDate(Date when, TimeZone tz)
public static final Date endOfDate(Date when, TimeZone tz)
public static final Date beginOfYear()
public static final Date beginOfYear(Date when, TimeZone tz)
public static final Date endOfYear()
public static final Date endOfYear(Date when, TimeZone tz)
public static final short twoMonthShort()
public static final short twoMonthShort(Date when, TimeZone tz)
public static final int yearOfDate(Date when, TimeZone tz)
when - The date.tz - The time zone; if null, the current time zone is assumed.localizedYearOfDate(java.util.Date, java.util.Locale, java.util.TimeZone)public static final int localizedYearOfDate(Date when, Locale locale, TimeZone tz)
Currently, only Locale.ZH_TW is supported, i.e.,
"year - 1911" and it's may be less than 0. Otherwise, it is the same
as yearOfDate(java.util.Date, java.util.TimeZone).
when - The date.locale - the locale; if null, the current locale is assumed.tz - The time zone; if null, the current time zone is assumed.yearOfDate(java.util.Date, java.util.TimeZone)public static final int monthOfDate(Date when, TimeZone tz)
when - The date.tz - The time zone; if null, the current time zone is assumed.public static final int monthOfDatePlus1(Date when, TimeZone tz)
when - The date.tz - The time zone; if null, the current time zone is assumed.public static final int dayMonthOfDate(Date when, TimeZone tz)
when - The date.tz - The time zone; if null, the current time zone is assumed.public static final Date add(Date when, TimeZone tz, int field, int amount)
when - The based date.tz - The time zone; if null, the current time zone is assumed.field - The time field.amount - The amount of date or time to be added to the field.public static final long subtract(Date date2, TimeZone tz, int field, Date date1)
date2 - The date2.tz - The time zone.field - The time field; e.g., Calendar.DATE, Calendar.YEAR, it's default value is Calendar.DATEdate1 - The date1.public static final Date merge(Date datePart, Date timePart, TimeZone tz)
datePart - The date part date.timePart - The time part date.tz - The time zone.Copyright © 2018. All rights reserved.