public final class DateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ISO_8601_DATETIME_FORMAT
It's default date/time format.
|
static java.lang.String |
ISO_8601_TIMESTAMP_FORMAT
It's default timestamp format.
|
static java.lang.String |
LOCAL_DATE_FORMAT |
static java.lang.String |
LOCAL_DATETIME_FORMAT |
static java.lang.String |
LOCAL_MONTH_DAY_FORMAT |
static java.lang.String |
LOCAL_TIME_FORMAT |
static java.util.TimeZone |
LOCAL_TIME_ZONE
The system default time zone
|
static java.lang.String |
LOCAL_TIMESTAMP_FORMAT |
static java.lang.String |
LOCAL_YEAR_FORMAT
Date format.
|
static java.lang.String |
RFC1123_DATE_FORMAT
This constant defines the date format specified by
RFC 1123 / RFC 822.
|
static java.util.TimeZone |
UTC_TIME_ZONE |
Modifier and Type | Method and Description |
---|---|
static java.util.Calendar |
asCalendar(java.util.Calendar c) |
static java.util.Calendar |
asCalendar(java.util.Date date) |
static java.util.Calendar |
asCalendar(long timeInMillis) |
static java.util.Calendar |
asCalendar(java.lang.String calendar) |
static java.util.Calendar |
asCalendar(java.lang.String calendar,
java.lang.String format) |
static java.util.Calendar |
asCalendar(java.lang.String calendar,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of Calendar. |
static java.sql.Date |
asDate(java.util.Calendar c) |
static java.sql.Date |
asDate(java.util.Date date) |
static java.sql.Date |
asDate(long timeInMillis) |
static java.sql.Date |
asDate(java.lang.String date) |
static java.sql.Date |
asDate(java.lang.String date,
java.lang.String format) |
static java.sql.Date |
asDate(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of java.sql.Date. |
static java.util.GregorianCalendar |
asGregorianCalendar(java.util.Calendar c) |
static java.util.GregorianCalendar |
asGregorianCalendar(java.util.Date date) |
static java.util.GregorianCalendar |
asGregorianCalendar(long timeInMillis) |
static java.util.GregorianCalendar |
asGregorianCalendar(java.lang.String calendar) |
static java.util.GregorianCalendar |
asGregorianCalendar(java.lang.String calendar,
java.lang.String format) |
static java.util.GregorianCalendar |
asGregorianCalendar(java.lang.String calendar,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of GregorianCalendar. |
static java.util.Date |
asJUDate(java.util.Calendar c) |
static java.util.Date |
asJUDate(java.util.Date date) |
static java.util.Date |
asJUDate(long timeInMillis) |
static java.util.Date |
asJUDate(java.lang.String date) |
static java.util.Date |
asJUDate(java.lang.String date,
java.lang.String format) |
static java.util.Date |
asJUDate(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of java.util.Date. |
static java.sql.Time |
asTime(java.util.Calendar c) |
static java.sql.Time |
asTime(java.util.Date date) |
static java.sql.Time |
asTime(long timeInMillis) |
static java.sql.Time |
asTime(java.lang.String date) |
static java.sql.Time |
asTime(java.lang.String date,
java.lang.String format) |
static java.sql.Time |
asTime(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of Time. |
static java.sql.Timestamp |
asTimestamp(java.util.Calendar c) |
static java.sql.Timestamp |
asTimestamp(java.util.Date date) |
static java.sql.Timestamp |
asTimestamp(long timeInMillis) |
static java.sql.Timestamp |
asTimestamp(java.lang.String date) |
static java.sql.Timestamp |
asTimestamp(java.lang.String date,
java.lang.String format) |
static java.sql.Timestamp |
asTimestamp(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of Timestamp. |
static javax.xml.datatype.XMLGregorianCalendar |
asXMLGregorianCalendar(java.util.Calendar c) |
static javax.xml.datatype.XMLGregorianCalendar |
asXMLGregorianCalendar(java.util.Date date) |
static javax.xml.datatype.XMLGregorianCalendar |
asXMLGregorianCalendar(long timeInMillis) |
static javax.xml.datatype.XMLGregorianCalendar |
asXMLGregorianCalendar(java.lang.String calendar) |
static javax.xml.datatype.XMLGregorianCalendar |
asXMLGregorianCalendar(java.lang.String calendar,
java.lang.String format) |
static javax.xml.datatype.XMLGregorianCalendar |
asXMLGregorianCalendar(java.lang.String calendar,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of XMLGregorianCalendar. |
static java.util.Calendar |
currentCalendar()
A new instance of
java.util.Calendar returned is based on
the current time in the default time zone with the default locale. |
static java.sql.Date |
currentDate()
A new instance of
java.sql.Date returned is based on the
current time in the default time zone with the default locale. |
static java.util.GregorianCalendar |
currentGregorianCalendar() |
static java.util.Date |
currentJUDate()
A new instance of
java.util.Date returned is based on the
current time in the default time zone with the default locale. |
static long |
currentMillis() |
static java.sql.Time |
currentTime()
A new instance of
java.sql.Time returned is based on the
current time in the default time zone with the default locale. |
static java.sql.Timestamp |
currentTimestamp()
A new instance of
java.sql.Timestamp returned is based on
the current time in the default time zone with the default locale. |
static javax.xml.datatype.XMLGregorianCalendar |
currentXMLGregorianCalendar() |
static java.lang.String |
format(java.util.Calendar c) |
static java.lang.String |
format(java.util.Calendar c,
java.lang.String format) |
static java.lang.String |
format(java.util.Calendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static java.lang.String |
format(java.util.Date date) |
static java.lang.String |
format(java.util.Date date,
java.lang.String format) |
static java.lang.String |
format(java.util.Date date,
java.lang.String format,
java.util.TimeZone timeZone) |
static void |
format(java.io.Writer writer,
java.util.Calendar c) |
static void |
format(java.io.Writer writer,
java.util.Calendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static void |
format(java.io.Writer writer,
java.util.Date date) |
static void |
format(java.io.Writer writer,
java.util.Date date,
java.lang.String format,
java.util.TimeZone timeZone) |
static void |
format(java.io.Writer writer,
javax.xml.datatype.XMLGregorianCalendar c) |
static void |
format(java.io.Writer writer,
javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static java.lang.String |
format(javax.xml.datatype.XMLGregorianCalendar c) |
static java.lang.String |
format(javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format) |
static java.lang.String |
format(javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static <T extends java.util.Calendar> |
roll(T c,
long amount,
CalendarUnit unit)
Adds or subtracts the specified amount of time to the given calendar
unit, based on the calendar's rules.
|
static <T extends java.util.Date> |
roll(T date,
long amount,
CalendarUnit unit)
Adds or subtracts the specified amount of time to the given calendar
unit, based on the calendar's rules.
|
static <T extends java.util.Calendar> |
roll(T c,
long amount,
java.util.concurrent.TimeUnit unit)
Adds or subtracts the specified amount of time to the given time unit,
based on the calendar's rules.
|
static <T extends java.util.Date> |
roll(T date,
long amount,
java.util.concurrent.TimeUnit unit)
Adds or subtracts the specified amount of time to the given time unit,
based on the calendar's rules.
|
public static final java.util.TimeZone UTC_TIME_ZONE
public static final java.util.TimeZone LOCAL_TIME_ZONE
public static final java.lang.String LOCAL_YEAR_FORMAT
public static final java.lang.String LOCAL_MONTH_DAY_FORMAT
public static final java.lang.String LOCAL_DATE_FORMAT
public static final java.lang.String LOCAL_TIME_FORMAT
public static final java.lang.String LOCAL_DATETIME_FORMAT
public static final java.lang.String LOCAL_TIMESTAMP_FORMAT
public static final java.lang.String ISO_8601_DATETIME_FORMAT
public static final java.lang.String ISO_8601_TIMESTAMP_FORMAT
public static final java.lang.String RFC1123_DATE_FORMAT
public static java.util.Date asJUDate(java.util.Calendar c)
public static java.util.Date asJUDate(java.util.Date date)
public static java.util.Date asJUDate(long timeInMillis)
public static java.util.Date asJUDate(java.lang.String date)
public static java.util.Date asJUDate(java.lang.String date, java.lang.String format)
public static java.util.Date asJUDate(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of java.util.Date.
null
is returned if the specified date
is null or empty.date
- format
- java.lang.IllegalArgumentException
- if the date given can't be parsed with specified format.public static java.sql.Date asDate(java.util.Calendar c)
public static java.sql.Date asDate(java.util.Date date)
public static java.sql.Date asDate(long timeInMillis)
public static java.sql.Date asDate(java.lang.String date)
public static java.sql.Date asDate(java.lang.String date, java.lang.String format)
public static java.sql.Date asDate(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of java.sql.Date.
null
is returned if the specified date
is null or empty.date
- format
- timeZone
- public static java.sql.Time asTime(java.util.Calendar c)
public static java.sql.Time asTime(java.util.Date date)
public static java.sql.Time asTime(long timeInMillis)
public static java.sql.Time asTime(java.lang.String date)
public static java.sql.Time asTime(java.lang.String date, java.lang.String format)
public static java.sql.Time asTime(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of Time.
null
is returned if the specified date
is null or empty.date
- format
- timeZone
- public static java.sql.Timestamp asTimestamp(java.util.Calendar c)
public static java.sql.Timestamp asTimestamp(java.util.Date date)
public static java.sql.Timestamp asTimestamp(long timeInMillis)
public static java.sql.Timestamp asTimestamp(java.lang.String date)
public static java.sql.Timestamp asTimestamp(java.lang.String date, java.lang.String format)
public static java.sql.Timestamp asTimestamp(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of Timestamp.
null
is returned if the specified date
is null or empty.date
- format
- timeZone
- public static java.util.Calendar asCalendar(java.util.Calendar c)
public static java.util.Calendar asCalendar(java.util.Date date)
public static java.util.Calendar asCalendar(long timeInMillis)
public static java.util.Calendar asCalendar(java.lang.String calendar)
public static java.util.Calendar asCalendar(java.lang.String calendar, java.lang.String format)
public static java.util.Calendar asCalendar(java.lang.String calendar, java.lang.String format, java.util.TimeZone timeZone)
calendar
with the specified format
to a new instance of Calendar.
null
is returned if the specified date
is null or empty.calendar
- format
- timeZone
- public static java.util.GregorianCalendar asGregorianCalendar(java.util.Calendar c)
public static java.util.GregorianCalendar asGregorianCalendar(java.util.Date date)
public static java.util.GregorianCalendar asGregorianCalendar(long timeInMillis)
public static java.util.GregorianCalendar asGregorianCalendar(java.lang.String calendar)
public static java.util.GregorianCalendar asGregorianCalendar(java.lang.String calendar, java.lang.String format)
public static java.util.GregorianCalendar asGregorianCalendar(java.lang.String calendar, java.lang.String format, java.util.TimeZone timeZone)
calendar
with the specified format
to a new instance of GregorianCalendar.
null
is returned if the specified date
is null or empty.calendar
- format
- timeZone
- public static javax.xml.datatype.XMLGregorianCalendar asXMLGregorianCalendar(java.util.Calendar c)
public static javax.xml.datatype.XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date)
public static javax.xml.datatype.XMLGregorianCalendar asXMLGregorianCalendar(long timeInMillis)
public static javax.xml.datatype.XMLGregorianCalendar asXMLGregorianCalendar(java.lang.String calendar)
public static javax.xml.datatype.XMLGregorianCalendar asXMLGregorianCalendar(java.lang.String calendar, java.lang.String format)
public static javax.xml.datatype.XMLGregorianCalendar asXMLGregorianCalendar(java.lang.String calendar, java.lang.String format, java.util.TimeZone timeZone)
calendar
with the specified format
to a new instance of XMLGregorianCalendar.
null
is returned if the specified date
is null or empty.calendar
- format
- timeZone
- public static long currentMillis()
System.currentTimeMillis()
public static java.sql.Time currentTime()
java.sql.Time
returned is based on the
current time in the default time zone with the default locale.public static java.sql.Date currentDate()
java.sql.Date
returned is based on the
current time in the default time zone with the default locale.public static java.sql.Timestamp currentTimestamp()
java.sql.Timestamp
returned is based on
the current time in the default time zone with the default locale.public static java.util.Date currentJUDate()
java.util.Date
returned is based on the
current time in the default time zone with the default locale.public static java.util.Calendar currentCalendar()
java.util.Calendar
returned is based on
the current time in the default time zone with the default locale.public static java.util.GregorianCalendar currentGregorianCalendar()
public static javax.xml.datatype.XMLGregorianCalendar currentXMLGregorianCalendar()
public static <T extends java.util.Date> T roll(T date, long amount, java.util.concurrent.TimeUnit unit)
N.roll(date, -5, TimeUnit.DAYS)
.
date
- amount
- unit
- public static <T extends java.util.Date> T roll(T date, long amount, CalendarUnit unit)
N.roll(date, -5, CalendarUnit.DAY)
.
date
- amount
- unit
- public static <T extends java.util.Calendar> T roll(T c, long amount, java.util.concurrent.TimeUnit unit)
N.roll(c, -5, TimeUnit.DAYS)
.
c
- amount
- unit
- public static <T extends java.util.Calendar> T roll(T c, long amount, CalendarUnit unit)
N.roll(c, -5, CalendarUnit.DAY)
.
c
- amount
- unit
- public static java.lang.String format(java.util.Date date)
public static java.lang.String format(java.util.Date date, java.lang.String format)
public static java.lang.String format(java.util.Date date, java.lang.String format, java.util.TimeZone timeZone)
public static void format(java.io.Writer writer, java.util.Date date)
public static void format(java.io.Writer writer, java.util.Date date, java.lang.String format, java.util.TimeZone timeZone)
public static java.lang.String format(java.util.Calendar c)
public static java.lang.String format(java.util.Calendar c, java.lang.String format)
public static java.lang.String format(java.util.Calendar c, java.lang.String format, java.util.TimeZone timeZone)
public static void format(java.io.Writer writer, java.util.Calendar c)
public static void format(java.io.Writer writer, java.util.Calendar c, java.lang.String format, java.util.TimeZone timeZone)
public static java.lang.String format(javax.xml.datatype.XMLGregorianCalendar c)
public static java.lang.String format(javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format)
public static java.lang.String format(javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format, java.util.TimeZone timeZone)
public static void format(java.io.Writer writer, javax.xml.datatype.XMLGregorianCalendar c)
public static void format(java.io.Writer writer, javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format, java.util.TimeZone timeZone)