Velocity Tools
Generic Tools
Tool Documentation
|
DateTool Reference Documentation
|
|
Tool for accessing, manipulating, and convertingjava.util.Date
and java.util.Calendar objects in Velocity templates. It
supports locales to format dates language and country specific.
Class |
| org.apache.velocity.tools.generic.DateTool |
Name |
| $date (this is the recommended name of the tool in
the Velocity context) |
Toolbox Configuration Example |
| <tool>
<key>date</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool> |
Author(s) |
| Nathan Bubna
|
- Method Overview
-
getDate() |
Returns a Date object representing the time at which this
method was invoked.
|
getCalendar() |
Returns a Calendar object representing the time at which this
method was invoked.
|
format() |
Returns a formatted string representing the specified date.
|
toDate() |
Returns a Date object representing the specified date.
|
toCalendar() |
Returns a Calendar object representing the specified date.
|
|
getDate()
|
|
Returns a Date object representing the time at which this
method was invoked.
String getDate(Locale locale)
|
- Parameters
-
- locale
-
An object of class
java.util.Locale that represents the locale
to be used to create the date.
- Returns
-
An object of class
java.util.Date representing the time at which this
method was invoked in the specified locale. If no locale is specified,
the system's default locale is used.
|
getCalendar()
|
|
Returns a Calendar object representing the time at which this
method was invoked.
String getCalendar(Locale locale)
|
- Parameters
-
- locale
-
An object of class
java.util.Locale that represents the locale
to be used to create the calendar.
- Returns
-
An object of class
java.util.Calendar representing the time at which this
method was invoked in the specified locale. If no locale is specified,
the system's default locale is used.
|
format()
|
|
Returns a formatted string representing the specified date.
String format(String format, Object obj)
|
String format(String format, Object obj, Locale locale)
|
- Parameters
-
- format
-
A string that represents the formatting instructions according to
java.text.SimpleDateFormat . See also below.
- obj
-
An object of class
java.util.Date or java.util.Calendar . It is
also possible to pass a string that represents a parsable date
according to java.text.DateFormat .
- locale
-
An object of class
java.util.Locale that represents the locale
to format the date for.
- Returns
-
The formatted date string in the specified locale or
null
if one or several input parameters are invalid. If no locale is specified,
the system's default locale is used instead.
This methods use the same formatting instructions as class
java.text.SimpleDateFormat .
Symbol Meaning Presentation Example
------ ------- ------------ -------
G era designator (Text) AD
y year (Number) 1996
M month in year (Text & Number) July & 07
d day in month (Number) 10
h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
m minute in hour (Number) 30
s second in minute (Number) 55
S millisecond (Number) 978
E day in week (Text) Tuesday
D day in year (Number) 189
F day of week in month (Number) 2 (2nd Wed in July)
w week in year (Number) 27
W week in month (Number) 2
a am/pm marker (Text) PM
k hour in day (1~24) (Number) 24
K hour in am/pm (0~11) (Number) 0
z time zone (Text) Pacific Standard Time
' escape for text (Delimiter)
'' single quote (Literal) '
Examples: "E, MMMM d" will result in "Tue, July 24"
"EEE, M-d (H:m)" will result in "Tuesday, 7-24 (14:12)"
|
|
|
toDate()
|
|
Returns a Date object representing the specified date.
- Parameters
-
- obj
-
The date to convert. The parameter can be an object of class
java.util.Date or java.util.Calendar . It is also possible to
pass a string that represents a parsable date according to
java.text.DateFormat .
- Returns
-
An object of class
java.util.Date representing the converted date
or of the input parameter is invalid.
|
toCalendar()
|
|
Returns a Calendar object representing the specified date.
Calendar toCalendar(Object obj)
|
- Parameters
-
- obj
-
The date to convert. The parameter can be an object of class
java.util.Date or java.util.Calendar . It is also possible to
pass a string that represents a parsable date according to
java.text.DateFormat .
- Returns
-
An object of class
java.util.Calendar representing the converted date
or of the input parameter is invalid.
|
|