|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.velocity.tools.generic.DateTool
Tool for working with Date
and Calendar
in Velocity templates.
This tool is entirely threadsafe, and has no instance members.
As such, the methods are highly interconnected, and overriding
key methods provides an easy way to create subclasses that use
a non-default calendar, locale, or timezone.
Constructor Summary | |
DateTool()
Default constructor. |
Method Summary | |
java.lang.String |
format(java.lang.String format,
java.lang.Object obj)
Converts the specified object to a date and returns a formatted string representing that date using the locale returned by getLocale() . |
static java.lang.String |
format(java.lang.String format,
java.lang.Object obj,
java.util.Locale locale)
Returns a formatted string representing the specified date and locale. |
java.util.Calendar |
getCalendar()
Returns a Calendar instance created using the timezone and
locale returned by getTimeZone() and getLocale(). |
java.util.Date |
getDate()
Returns a Date derived from the result of getCalendar() |
java.lang.String |
getFormattedDate(java.lang.String format)
Returns a formatted string representing the date as returned by getDate() . |
java.util.Locale |
getLocale()
|
static java.util.Calendar |
getSystemCalendar()
|
static java.util.Date |
getSystemDate()
|
java.util.TimeZone |
getTimeZone()
|
java.util.Calendar |
toCalendar(java.lang.Object obj)
Converts an object to an instance of Calendar using the
locale returned by getLocale() if necessary. |
static java.util.Calendar |
toCalendar(java.lang.Object obj,
java.util.Locale locale)
Converts an object to an instance of Calendar using the
locale returned by getLocale() if necessary. |
static java.util.Date |
toDate(java.lang.Object obj)
Converts an object to an instance of Date . |
java.util.Date |
toDate(java.lang.String format,
java.lang.Object obj)
Converts an object to an instance of Date using the
specified format and the Locale returned by
getLocale() if the object is not already an instance
of Date or Calendar. |
static java.util.Date |
toDate(java.lang.String format,
java.lang.Object obj,
java.util.Locale locale)
Converts an object to an instance of Date using the
specified format and Locale if the object is not already
an instance of Date or Calendar. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public DateTool()
Method Detail |
public static final java.util.Date getSystemDate()
Date
public static final java.util.Calendar getSystemCalendar()
Calendar
public java.util.Locale getLocale()
Locale
public java.util.TimeZone getTimeZone()
TimeZone
public java.util.Date getDate()
Date
derived from the result of getCalendar()
Date
derived from the result of getCalendar()
public java.util.Calendar getCalendar()
Calendar
instance created using the timezone and
locale returned by getTimeZone() and getLocale(). This allows subclasses
to easily override the default locale and timezone used by this tool.
Sub-classes may override this method to return a Calendar instance
not based on the system date.
Doing so will also cause the getDate(), getNormalDate(),
getFormattedDate(), and toString() methods to return dates equivalent
to the Calendar returned by this method, because those methods return
values derived from the result of this method.
Calendar
instance created using the results of
getTimeZone()
and getLocale()
.Calendar.getInstance(TimeZone zone, Locale aLocale)
public java.lang.String getFormattedDate(java.lang.String format)
getDate()
.
This method uses the same formatting instructions as
SimpleDateFormat
:
format
- the formatting instructions
getDate()
or null
if the parameters
are invalidformat(String format, Object obj, Locale locale)
public java.lang.String format(java.lang.String format, java.lang.Object obj)
getLocale()
.
This method uses the same formatting instructions as
SimpleDateFormat
:
format
- the formatting instructionsobj
- the date object to be formatted
null
if the parameters are invalidformat(String format, Object obj, Locale locale)
public static java.lang.String format(java.lang.String format, java.lang.Object obj, java.util.Locale locale)
This method uses the same formatting instructions as
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)"
format
- the formatting instructionsobj
- the date to formatlocale
- the Locale
to format the date for
null
if the parameters are invalidpublic static java.util.Date toDate(java.lang.Object obj)
Date
. Uses a
DateFormat to parse the string value of the object if it is not
an instance of Date or Calendar or Long.
obj
- the date to convert
Date
or null
if no
conversion is possiblepublic java.util.Date toDate(java.lang.String format, java.lang.Object obj)
Date
using the
specified format and the Locale
returned by
getLocale()
if the object is not already an instance
of Date or Calendar.
format
- - the format the date is inobj
- - the date to convert
Date
or null
if no
conversion is possibletoDate(String format, Object obj, Locale locale)
public static java.util.Date toDate(java.lang.String format, java.lang.Object obj, java.util.Locale locale)
Date
using the
specified format and Locale
if the object is not already
an instance of Date or Calendar.
format
- - the format the date is inobj
- - the date to convertlocale
- - the Locale
Date
or null
if no
conversion is possibleSimpleDateFormat.parse(java.lang.String, java.text.ParsePosition)
public java.util.Calendar toCalendar(java.lang.Object obj)
Calendar
using the
locale returned by getLocale()
if necessary.
obj
- the date to convert
toCalendar(Object obj, Locale locale)
public static java.util.Calendar toCalendar(java.lang.Object obj, java.util.Locale locale)
Calendar
using the
locale returned by getLocale()
if necessary.
obj
- the date to convertlocale
- the locale used
toDate(String format, Object obj, Locale locale)
,
Calendar
public java.lang.String toString()
toString
in class java.lang.Object
getDate()
as a string
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |