public final class Dates extends Object
Collection of EL functions for date and time: of:formatDate()
, of:formatDateWithTimezone()
,
of:addXxx()
like of:addDays()
, of:xxxBetween()
like of:daysBetween()
,
of:getMonths()
, of:getShortMonths()
, of:getDaysOfWeek()
, of:getShortDaysOfWeek()
,
of:getMonth()
, of:getShortMonth()
, of:getDayOfWeek()
and of:getShortDayOfWeek()
.
Modifier and Type | Method and Description |
---|---|
static Date |
addDays(Date date,
int days)
Returns a new date instance which is a sum of the given date and the given amount of days.
|
static Date |
addHours(Date date,
int hours)
Returns a new date instance which is a sum of the given date and the given amount of hours.
|
static Date |
addMinutes(Date date,
int minutes)
Returns a new date instance which is a sum of the given date and the given amount of minutes.
|
static Date |
addMonths(Date date,
int months)
Returns a new date instance which is a sum of the given date and the given amount of months.
|
static Date |
addSeconds(Date date,
int seconds)
Returns a new date instance which is a sum of the given date and the given amount of seconds.
|
static Date |
addWeeks(Date date,
int weeks)
Returns a new date instance which is a sum of the given date and the given amount of weeks.
|
static Date |
addYears(Date date,
int years)
Returns a new date instance which is a sum of the given date and the given amount of years.
|
static int |
daysBetween(Date start,
Date end)
Returns the amount of days between two given dates.
|
static String |
formatDate(Date date,
String pattern)
Format the given date in the given pattern with system default timezone.
|
static String |
formatDateWithTimezone(Date date,
String pattern,
Object timezone)
Format the given date in the given pattern with the given timezone.
|
static String |
getDayOfWeek(Integer dayOfWeekNumber)
Returns the day of week name from the mapping associated with the given day of week number in ISO 8601 order
(Monday first) for the current locale.
|
static Map<String,Integer> |
getDaysOfWeek()
Returns a mapping of day of week names in ISO 8601 order (Monday first) for the current locale.
|
static String |
getMonth(Integer monthNumber)
Returns the month name from the mapping associated with the given month number for the current locale.
|
static Map<String,Integer> |
getMonths()
Returns a mapping of month names by month numbers for the current locale.
|
static String |
getShortDayOfWeek(Integer dayOfWeekNumber)
Returns the short day of week name from the mapping associated with the given day of week number in ISO 8601
order (Monday first) for the current locale.
|
static Map<String,Integer> |
getShortDaysOfWeek()
Returns a mapping of short day of week names in ISO 8601 order (Monday first) for the current locale.
|
static String |
getShortMonth(Integer monthNumber)
Returns the short month name from the mapping associated with the given month number for the current locale.
|
static Map<String,Integer> |
getShortMonths()
Returns a mapping of short month names by month numbers for the current locale.
|
static long |
hoursBetween(Date start,
Date end)
Returns the amount of hours between two given dates.
|
static long |
minutesBetween(Date start,
Date end)
Returns the amount of minutes between two given dates.
|
static int |
monthsBetween(Date start,
Date end)
Returns the amount of months between two given dates.
|
static long |
secondsBetween(Date start,
Date end)
Returns the amount of seconds between two given dates.
|
static int |
weeksBetween(Date start,
Date end)
Returns the amount of weeks between two given dates.
|
static int |
yearsBetween(Date start,
Date end)
Returns the amount of years between two given dates.
|
public static String formatDate(Date date, String pattern)
title
attribute of an UI component, or the itemLabel
attribute
of select item, or wherever you can't use the <f:convertDateTime>
tag. The format locale will
be set to the one as obtained by Faces.getLocale()
.date
- The date to be formatted in the given pattern.pattern
- The pattern to format the given date in.NullPointerException
- When the pattern is null
.formatDateWithTimezone(Date, String, Object)
public static String formatDateWithTimezone(Date date, String pattern, Object timezone)
title
attribute of an UI component, or the itemLabel
attribute of
select item, or wherever you can't use the <f:convertDateTime>
tag. The format locale will be
set to the one as obtained by Faces.getLocale()
.date
- The date to be formatted in the given pattern.pattern
- The pattern to format the given date in.timezone
- The timezone to format the given date with, can be either timezone ID as string or
TimeZone
object.NullPointerException
- When the pattern is null
.public static Date addYears(Date date, int years)
date
- The date to add the given amount of years to.years
- The amount of years to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static Date addMonths(Date date, int months)
date
- The date to add the given amount of months to.months
- The amount of months to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static Date addWeeks(Date date, int weeks)
date
- The date to add the given amount of weeks to.weeks
- The amount of weeks to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static Date addDays(Date date, int days)
date
- The date to add the given amount of days to.days
- The amount of days to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static Date addHours(Date date, int hours)
date
- The date to add the given amount of hours to.hours
- The amount of hours to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static Date addMinutes(Date date, int minutes)
date
- The date to add the given amount of minutes to.minutes
- The amount of minutes to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static Date addSeconds(Date date, int seconds)
date
- The date to add the given amount of seconds to.seconds
- The amount of seconds to be added to the given date. It can be negative.NullPointerException
- When the date is null
.public static int yearsBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static int monthsBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static int weeksBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static int daysBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static long hoursBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static long minutesBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static long secondsBetween(Date start, Date end)
start
- The start date.end
- The end date.NullPointerException
- When a date is null
.public static Map<String,Integer> getMonths()
<f:selectItems>
which shows all
months. The locale is obtained by Faces.getLocale()
. The mapping is per locale stored in a local cache
to improve retrieving performance.DateFormatSymbols.getMonths()
public static Map<String,Integer> getShortMonths()
<f:selectItems>
which shows all
short months. The locale is obtained by Faces.getLocale()
. The mapping is per locale stored in a local
cache to improve retrieving performance.DateFormatSymbols.getShortMonths()
public static Map<String,Integer> getDaysOfWeek()
<f:selectItems>
which shows all days of week. The locale is obtained by Faces.getLocale()
. The mapping is per locale
stored in a local cache to improve retrieving performance.DateFormatSymbols.getWeekdays()
public static Map<String,Integer> getShortDaysOfWeek()
<f:selectItems>
which shows all short days of week. The locale is obtained by Faces.getLocale()
. The mapping is per locale
stored in a local cache to improve retrieving performance.DateFormatSymbols.getShortWeekdays()
public static String getMonth(Integer monthNumber)
Faces.getLocale()
.monthNumber
- The month number to return the month name from the mapping for.public static String getShortMonth(Integer monthNumber)
Faces.getLocale()
.monthNumber
- The month number to return the short month name from the mapping for.public static String getDayOfWeek(Integer dayOfWeekNumber)
Faces.getLocale()
.dayOfWeekNumber
- The day of week number to return the day of week name from the mapping for.public static String getShortDayOfWeek(Integer dayOfWeekNumber)
Faces.getLocale()
.dayOfWeekNumber
- The day of week number to return the short day of week name from the mapping for.Copyright © 2012–2016 OmniFaces. All rights reserved.