类 ComparisonDateTool.Comparison
java.lang.Object
org.apache.velocity.tools.generic.ComparisonDateTool.Comparison
- 封闭类:
- ComparisonDateTool
-
构造器概要
构造器构造器说明Comparison(Calendar now, Calendar then, int type, int depth, boolean abbr, Locale loc) Comparison object constructor -
方法概要
修饰符和类型方法说明abbr(boolean abbr) Sets whether or not this comparison is to be rendered in abbreviated form or not.depth(int depth) Set the maximum number of units to render for this comparison.getAbbr()This is equivalent to callingabbr(boolean abbr)withtrueas the argument, thus setting this comparison to be rendered in abbreviated form.longgetDays()Return the number of days between the dates being compared.Sets this comparison to be rendered as aComparisonDateTool.difference(java.lang.Object, java.lang.Object).getExact()Sets this comparison to be rendered as if it where generated using theComparisonDateTool.timespan(Object now, Object then)method.protected final int[]Internal helper returning a cached map of all exact bygone time units per field.getFull()Sets thedepth(int depth)to which this comparison is rendered to the maximum number of time units available to the tool.longgetHours()Return the number of hours between the dates being compared.longReturn the number of milliseconds between the dates being compared.longReturn the number of minutes between the dates being compared.longReturn the approximate number of months between the dates being compared, or the bygone number of months after the bygone number of years in exact mode.Sets this comparison to be rendered as if it where generated using theComparisonDateTool.whenIs(Object now, Object then)method.longReturn the number of seconds between the dates being compared.longgetWeeks()Return the number of weeks between the dates being compared.longgetYears()Return the approximate number of years between the dates being compared, or the bygone number of years in exact mode.Sets the locale used to look up the textual portions of the rendering.toString()Renders this comparison to a String.protected StringtoString(long diff, int maxUnitDepth) Converts the specified positive duration of milliseconds into larger units up to the specified number of positive units, beginning with the largest positive unit.
-
构造器详细资料
-
Comparison
Comparison object constructor- 参数:
now- The date to use as representative of "now"then- The secondary datetype- comparison typedepth- units depthabbr- whether to abbreviate unitsloc- locale to use
-
-
方法详细资料
-
abbr
Sets whether or not this comparison is to be rendered in abbreviated form or not. By default, it is not abbreviated.- 参数:
abbr- flag value- 返回:
- new Comparison object
-
depth
Set the maximum number of units to render for this comparison. By default, this is set to 1 unit.- 参数:
depth- max units depth- 返回:
- new Comparison object
-
locale
Sets the locale used to look up the textual portions of the rendering. This defaults to the Locale configured for this tool, if any. If no locale was configured, this defaults to the system default.- 参数:
loc- locale to use- 返回:
- new Comparison object
-
getExactDifference
protected final int[] getExactDifference()Internal helper returning a cached map of all exact bygone time units per field.- 返回:
- cached exact difference holder, as a calendar object
-
getYears
public long getYears()Return the approximate number of years between the dates being compared, or the bygone number of years in exact mode.- 返回:
- years
-
getMonths
public long getMonths()Return the approximate number of months between the dates being compared, or the bygone number of months after the bygone number of years in exact mode.- 返回:
- months
-
getWeeks
public long getWeeks()Return the number of weeks between the dates being compared.- 返回:
- weeks
-
getDays
public long getDays()Return the number of days between the dates being compared.- 返回:
- days
-
getHours
public long getHours()Return the number of hours between the dates being compared.- 返回:
- hours
-
getMinutes
public long getMinutes()Return the number of minutes between the dates being compared.- 返回:
- minutes
-
getSeconds
public long getSeconds()Return the number of seconds between the dates being compared.- 返回:
- seconds
-
getMilliseconds
public long getMilliseconds()Return the number of milliseconds between the dates being compared.- 返回:
- milliseconds
-
getFull
Sets thedepth(int depth)to which this comparison is rendered to the maximum number of time units available to the tool. By default, there are 8 units available, but the tool may be configured to "skip" any of the standard units, thus shortening the maximum depth.- 返回:
- new Comparison object
-
getDifference
Sets this comparison to be rendered as aComparisonDateTool.difference(java.lang.Object, java.lang.Object). This effectively means that the comparison will render as a period of time, without any suffix to describe the relative position of the dates being compared (e.g. "later" or "ago").- 返回:
- new Comparison object
-
getRelative
Sets this comparison to be rendered as if it where generated using theComparisonDateTool.whenIs(Object now, Object then)method. This effectively means that the comparison will render with a suffix to describe the relative position of the dates being compared (e.g. "later" or "ago").- 返回:
- new Comparison object
-
getExact
Sets this comparison to be rendered as if it where generated using theComparisonDateTool.timespan(Object now, Object then)method. This effectively means that the comparison will render with a suffix to describe the relative position of the dates being compared (e.g. "later" or "ago").- 返回:
- new Comparison object
-
getAbbr
This is equivalent to callingabbr(boolean abbr)withtrueas the argument, thus setting this comparison to be rendered in abbreviated form.- 返回:
- new Comparison object
-
toString
Converts the specified positive duration of milliseconds into larger units up to the specified number of positive units, beginning with the largest positive unit. e.g.toString(181453, 3, false, null)will return "3 minutes 1 second 453 milliseconds",toString(181453, 2, false, null)will return "3 minutes 1 second", andtoString(180000, 2, true, null)will return "3 min".- 参数:
diff- milliseconds, or, in exact mode, time unit indexmaxUnitDepth- maximum unit depth- 返回:
- string representation of the difference
-
toString
Renders this comparison to a String.
-