public class DateUtil
extends java.lang.Object
DateUtil
is a utility class that provides easy access to
commonly used dates and for parsing/reading ISO8601 date strings.Constructor and Description |
---|
DateUtil()
Initializes a DateUtil with the first day of week being the Monday.
|
DateUtil(int firstDayOfWeek)
Initializes a DateUtil with a custom first day of the week.
|
Modifier and Type | Method and Description |
---|---|
static java.text.DateFormat |
getDateFormat(java.lang.String pattern,
java.text.DateFormat defaultDateFormat,
java.util.Locale locale)
Returns a date format object, based on either a custom date pattern or a default date pattern, and a
Locale |
static java.text.DateFormat |
getDateFormat(java.lang.String pattern,
java.util.Locale locale)
Returns a date format object, based on a date pattern and a
Locale |
static java.text.DateFormat |
getDateFormat(java.lang.String pattern,
java.lang.String defaultPattern,
java.util.Locale locale)
Returns a date format object, based on either a custom date pattern or a default date pattern, and a
Locale |
static java.lang.String |
getISO8601Date(java.util.Calendar calendar)
Generate a full ISO 8601 date: "YYYY-MM-DDTHH:mm:ss.SSSZ".
|
static java.lang.String |
getISO8601Date(java.util.Date date)
Generate a full ISO 8601 date: "YYYY-MM-DDTHH:mm:ss.SSSZ".
|
static java.lang.String |
getISO8601Date(java.util.Date date,
java.util.TimeZone timeZone)
Generate a full ISO 8601 date: "YYYY-MM-DDTHH:mm:ss.SSSZ".
|
static java.lang.String |
getISO8601DateAndTimeNoMillis(java.util.Calendar calendar)
Generate a ISO 8601 date with date and time, but without the milliseconds
part: "YYYY-MM-DDTHH:mm:ssZ".
|
static java.lang.String |
getISO8601DateAndTimeNoMillis(java.util.Date date)
Generate a ISO 8601 date with date and time, but without the milliseconds
part: "YYYY-MM-DDTHH:mm:ssZ".
|
static java.lang.String |
getISO8601DateAndTimeNoMillis(java.util.Date date,
java.util.TimeZone timeZone)
Generate a ISO 8601 date with date and time, but without the milliseconds
part: "YYYY-MM-DDTHH:mm:ssZ".
|
static java.lang.String |
getISO8601DateNoTime(java.util.Calendar calendar)
Generate a ISO 8601 date in the pure date form: "YYYY-MM-DD"
|
static java.lang.String |
getISO8601DateNoTime(java.util.Date date)
Generate a ISO 8601 date in the pure date form: "YYYY-MM-DD".
|
static java.lang.String |
getISO8601DateNoTime(java.util.Date date,
java.util.TimeZone timeZone)
Generate a ISO 8601 date in the pure date form: "YYYY-MM-DD".
|
java.util.Calendar |
getLastYearStart() |
java.util.Calendar |
getMonthStart() |
java.util.Calendar |
getNow() |
java.util.Calendar |
getThreeMonthsAgo() |
java.util.Calendar |
getToday() |
java.util.Calendar |
getWeekStart() |
java.util.Calendar |
getYearStart() |
static java.util.Calendar |
parseISO8601(java.lang.String iso8601Date)
Parse the given string in ISO 8601 format and build a Calendar object.
|
static java.util.Calendar |
parseISO8601(java.lang.String iso8601Date,
java.util.TimeZone defaultTimeZone)
Parse the given string in ISO 8601 format and build a Calendar object.
|
public DateUtil()
public DateUtil(int firstDayOfWeek)
firstDayOfWeek
- the first day of the week.Calendar.DAY_OF_WEEK
public final java.util.Calendar getLastYearStart()
public final java.util.Calendar getYearStart()
public final java.util.Calendar getThreeMonthsAgo()
public final java.util.Calendar getMonthStart()
public final java.util.Calendar getWeekStart()
Calendar.setFirstDayOfWeek(int)
!public final java.util.Calendar getToday()
public final java.util.Calendar getNow()
public static java.util.Calendar parseISO8601(java.lang.String iso8601Date) throws InvalidDateException
iso8601Date
- the date in ISO 8601 formatInvalidDateException
- if the date string is not validpublic static java.util.Calendar parseISO8601(java.lang.String iso8601Date, java.util.TimeZone defaultTimeZone) throws InvalidDateException
iso8601Date
- the date in ISO 8601 formatdefaultTimeZone
- the timezone to use when the timezone is not specified in the
iso-8601 string (if null
, the system default timezone will be used)InvalidDateException
- if the date string is not validpublic static java.lang.String getISO8601Date(java.util.Calendar calendar)
calendar
- a Calendar instancepublic static java.lang.String getISO8601Date(java.util.Date date)
date
- a Date instance representing a UTC timepublic static java.lang.String getISO8601Date(java.util.Date date, java.util.TimeZone timeZone)
date
- a Date instancetimeZone
- the timeZone of the datepublic static java.lang.String getISO8601DateAndTimeNoMillis(java.util.Calendar calendar)
calendar
- a Calendar instancepublic static java.lang.String getISO8601DateAndTimeNoMillis(java.util.Date date)
date
- a Date instance representing a UTC timepublic static java.lang.String getISO8601DateAndTimeNoMillis(java.util.Date date, java.util.TimeZone timeZone)
date
- a Date instancetimeZone
- the timeZone of the datepublic static java.lang.String getISO8601DateNoTime(java.util.Calendar calendar)
calendar
- a Calendar instancepublic static java.lang.String getISO8601DateNoTime(java.util.Date date)
date
- a Date instance representing a UTC time.public static java.lang.String getISO8601DateNoTime(java.util.Date date, java.util.TimeZone timeZone)
date
- a Date instance representing a datetimeZone
- the timeZone of the datepublic static java.text.DateFormat getDateFormat(java.lang.String pattern, java.util.Locale locale)
Locale
pattern
- Date patternlocale
- Date format localisationnull
public static java.text.DateFormat getDateFormat(java.lang.String pattern, java.lang.String defaultPattern, java.util.Locale locale)
Locale
pattern
- User provided date patterndefaultPattern
- Default date format used if the user provided date pattern was not validlocale
- Date format localisationpublic static java.text.DateFormat getDateFormat(java.lang.String pattern, java.text.DateFormat defaultDateFormat, java.util.Locale locale)
Locale
pattern
- User provided date patterndefaultDateFormat
- Default date format used if the user provided date pattern was not validlocale
- Date format localisationCopyright © 2010 - 2020 Adobe. All Rights Reserved