类 ComparisonDateTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.FormatConfig
org.apache.velocity.tools.generic.DateTool
org.apache.velocity.tools.generic.ComparisonDateTool
- 所有已实现的接口:
Serializable
Tool for comparing Date and Calendar values
in Velocity templates. This is a subclass of DateTool
and thus provides all the functionality of that tool and
augments it with the ability to find the relationship between
any date and the current date, or between any two dates.
This comparison can result in either a textual representation
of the relationship (e.g. "3 weeks, 2 days ago", "tomorrow", or
"3 hrs away") or the value of a specific time unit may be requested.
When using the textual representations, you can configure the
tool to use alternate resource bundles and to skip over units
you do not want to be included.
Example of formatting the "current" date:
$date.whenIs('2005-07-04') -> 1 year ago
$date.whenIs('2007-02-15').full -> 1 year 32 weeks 2 days 17 hours 38 minutes 44 seconds 178 milliseconds ago
$date.whenIs('2007-02-15').days -> -730
$date.whenIs($date.calendar) -> now
$date.whenIs('2005-07-04', '2005-07-04') -> same time
$date.difference('2005-07-04','2005-07-04') -> 0 milliseconds
$date.difference('2005-07-04','2007-02-15').abbr -> 1 yr
Example tools.xml config (if you want to use this with VelocityView):
<tools>
<toolbox scope="application">
<tool class="org.apache.velocity.tools.generic.ComparisonDateTool"
format="yyyy-MM-dd" depth="1" skip="month,week,millisecond"
bundle="org.apache.velocity.tools.generic.times"/>
</toolbox>
</tools>
- 从以下版本开始:
- VelocityTools 1.4
- 版本:
- $Revision$ $Date: 2006-04-04 12:35:17 -0700 (Tue, 04 Apr 2006) $
- 作者:
- Nathan Bubna, Chris Townsen
- 另请参阅:
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明protected static final Stringprotected static final Stringprotected static final Stringstatic final StringThe key used for specifying a default locale via toolbox params.protected static final int[]protected static final Stringprotected static final intprotected static final Stringstatic final StringThe default path of the relative format resource bundles.static final StringThe key used for specifying a different default depth via toolbox params.protected static final intprotected static final Stringprotected static final intprotected static final int[]protected static final Stringstatic final longThe number of milliseconds in a day.static final longThe number of milliseconds in an hour.static final longThe number of millseconds in a minute.static final longAn approximation of the number of milliseconds in a month.static final longThe number of milliseconds in a second.static final longThe number of milliseconds in a week.static final longAn approximation of the number of milliseconds in a year.protected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final intprotected static final Stringstatic final StringThe key used for specifying time units to be skipped over.protected static final MapArray of all time unit message keys to their millisecond conversion factor.protected static final String[]protected static final Stringprotected static final Stringprotected static final String从类继承的字段 org.apache.velocity.tools.generic.DateTool
TIMEZONE_KEY从类继承的字段 org.apache.velocity.tools.generic.FormatConfig
DEFAULT_FORMAT, FORMAT_KEY从类继承的字段 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected ComparisonDateTool.ComparisonInternal comparison method.protected voidconfigure(ValueParser values) Calls the superclass implementation, then looks for a bundle name and any time units to be skipped.difference(Object now, Object then) Returns aComparisonDateTool.Comparisonbetween the result of the second specified date and the first specified date.protected StringRetrieves the specified text resource.Returns aComparisonDateTool.Comparisonbetween the result of the second specified date and the first specified date.static longtoDays(long ms) Returns the number of whole Days in the specified number of milliseconds.static longtoHours(long ms) Returns the number of whole Hours in the specified number of milliseconds.static longtoMinutes(long ms) Returns the number of whole Minutes in the specified number of milliseconds.static longtoMonths(long ms) Returns the number of whole Months in the specified number of milliseconds.static longtoSeconds(long ms) Returns the number of whole Seconds in the specified number of milliseconds.static longtoWeeks(long ms) Returns the number of whole Weeks in the specified number of milliseconds.static longtoYears(long ms) Returns the number of whole Years in the specified number of milliseconds.Returns aComparisonDateTool.Comparisonbetween the result ofDateTool.getCalendar()and the specified date.Returns aComparisonDateTool.Comparisonbetween the second specified date and the first specified date.从类继承的方法 org.apache.velocity.tools.generic.DateTool
format, format, format, format, format, format, format, get, get, getCalendar, getDate, getDateFormat, getDateFormat, getDay, getDay, getMonth, getMonth, getSystemCalendar, getSystemDate, getSystemTime, getTimeZone, getValue, getValue, getValue, getYear, getYear, setTimeZone, toCalendar, toCalendar, toCalendar, toCalendar, toCalendar, toDate, toDate, toDate, toDate, toDate, toDate, toLocalizedPattern, toString从类继承的方法 org.apache.velocity.tools.generic.FormatConfig
getFormat, setFormat从类继承的方法 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocale从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
MILLIS_PER_SECOND
public static final long MILLIS_PER_SECONDThe number of milliseconds in a second.- 另请参阅:
-
MILLIS_PER_MINUTE
public static final long MILLIS_PER_MINUTEThe number of millseconds in a minute.- 另请参阅:
-
MILLIS_PER_HOUR
public static final long MILLIS_PER_HOURThe number of milliseconds in an hour.- 另请参阅:
-
MILLIS_PER_DAY
public static final long MILLIS_PER_DAYThe number of milliseconds in a day.- 另请参阅:
-
MILLIS_PER_WEEK
public static final long MILLIS_PER_WEEKThe number of milliseconds in a week.- 另请参阅:
-
MILLIS_PER_MONTH
public static final long MILLIS_PER_MONTHAn approximation of the number of milliseconds in a month.- 另请参阅:
-
MILLIS_PER_YEAR
public static final long MILLIS_PER_YEARAn approximation of the number of milliseconds in a year.- 另请参阅:
-
BUNDLE_NAME_KEY
The key used for specifying a default locale via toolbox params.- 另请参阅:
-
DEPTH_KEY
The key used for specifying a different default depth via toolbox params.- 另请参阅:
-
SKIPPED_UNITS_KEY
The key used for specifying time units to be skipped over.- 另请参阅:
-
DEFAULT_BUNDLE_NAME
The default path of the relative format resource bundles.- 另请参阅:
-
MILLISECOND_KEY
- 另请参阅:
-
SECOND_KEY
- 另请参阅:
-
MINUTE_KEY
- 另请参阅:
-
HOUR_KEY
- 另请参阅:
-
DAY_KEY
- 另请参阅:
-
WEEK_KEY
- 另请参阅:
-
MONTH_KEY
- 另请参阅:
-
YEAR_KEY
- 另请参阅:
-
TIME_UNITS
Array of all time unit message keys to their millisecond conversion factor. -
CURRENT_PREFIX
- 另请参阅:
-
AFTER_KEY
- 另请参阅:
-
BEFORE_KEY
- 另请参阅:
-
EQUAL_KEY
- 另请参阅:
-
ZERO_KEY
- 另请参阅:
-
ABBR_SUFFIX
- 另请参阅:
-
ONE_DAY_SUFFIX
- 另请参阅:
-
PLURAL_SUFFIX
- 另请参阅:
-
CURRENT_TYPE
protected static final int CURRENT_TYPE- 另请参阅:
-
RELATIVE_TYPE
protected static final int RELATIVE_TYPE- 另请参阅:
-
DIFF_TYPE
protected static final int DIFF_TYPE- 另请参阅:
-
EXACT_TYPE
protected static final int EXACT_TYPE- 另请参阅:
-
CALENDAR_FIELDS
protected static final int[] CALENDAR_FIELDS -
FIELD_MAXIMA
protected static final int[] FIELD_MAXIMA -
UNIT_KEYS
-
-
构造器详细资料
-
ComparisonDateTool
public ComparisonDateTool()
-
-
方法详细资料
-
configure
Calls the superclass implementation, then looks for a bundle name and any time units to be skipped. -
getText
Retrieves the specified text resource.- 参数:
key- keylocale- locale- 返回:
- text resource
-
toYears
public static long toYears(long ms) Returns the number of whole Years in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- years
-
toMonths
public static long toMonths(long ms) Returns the number of whole Months in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- months
-
toWeeks
public static long toWeeks(long ms) Returns the number of whole Weeks in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- weeks
-
toDays
public static long toDays(long ms) Returns the number of whole Days in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- days
-
toHours
public static long toHours(long ms) Returns the number of whole Hours in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- hours
-
toMinutes
public static long toMinutes(long ms) Returns the number of whole Minutes in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- minutes
-
toSeconds
public static long toSeconds(long ms) Returns the number of whole Seconds in the specified number of milliseconds.- 参数:
ms- milliseconds- 返回:
- seconds
-
whenIs
Returns aComparisonDateTool.Comparisonbetween the result ofDateTool.getCalendar()and the specified date. The default rendering of that Comparison will be the largest unit difference between the dates followed by a description of their relative position.- 参数:
then- The date in question- 返回:
ComparisonDateTool.Comparisonobject
-
whenIs
Returns aComparisonDateTool.Comparisonbetween the second specified date and the first specified date. The default rendering of that Comparison will be the largest unit difference between the dates followed by a description of their relative position.- 参数:
now- The date to use as representative of "now"then- The date in question- 返回:
ComparisonDateTool.Comparisonobject
-
difference
Returns aComparisonDateTool.Comparisonbetween the result of the second specified date and the first specified date. The default rendering of that Comparison will be the largest unit difference between the dates.- 参数:
now- The date to use as representative of "now"then- The secondary date- 返回:
ComparisonDateTool.Comparisonobject
-
timespan
Returns aComparisonDateTool.Comparisonbetween the result of the second specified date and the first specified date. The default rendering of that Comparison will be the decreasing sequence of bygone time units between the dates.- 参数:
now- The date to use as representative of "now"then- The secondary date- 返回:
ComparisonDateTool.Comparisonobject
-
compare
Internal comparison method.- 参数:
now- The date to use as representative of "now"then- The secondary datetype- Difference type- 返回:
ComparisonDateTool.Comparisonobject
-