Class Date
Format Date object in different ways.
The date tag will allow you to format a Date in a quick and easy way. You can specify a custom format (eg. "dd/MM/yyyy hh:mm"), you can generate easy readable notations (like "in 2 hours, 14 minutes"), or you can just fall back on a predefined format with key 'struts.date.format' in your properties file.
If that key is not defined, it will finally fall back to the default DateFormat.MEDIUM formatting.
Note: If the requested Date object isn't found on the stack, a blank will be returned.
Note: Since Struts 6.0.0 a new Java 8 API has been used to format the Date, it's based on DateTimeFormatter which uses a bit different patterns.
Configurable attributes are:
- name
- nice
- format
Following how the date component will work, depending on the value of nice attribute (which by default is false) and the format attribute.
Condition 1: With nice attribute as true
| i18n key | default | 
| struts.date.format.past | {0} ago | 
| struts.date.format.future | in {0} | 
| struts.date.format.seconds | an instant | 
| struts.date.format.minutes | {0,choice,1#one minute|1<{0} minutes} | 
| struts.date.format.hours | {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1<, {1} minutes} | 
| struts.date.format.days | {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours} | 
| struts.date.format.years | {0,choice,1#one year|1<{0} years}{1,choice,0#|1#, one day|1<, {1} days} | 
Condition 2: With nice attribute as false and format attribute is specified eg. dd/MM/yyyyy
In this case the format attribute will be used.
Condition 3: With nice attribute as false and no format attribute is specified
| i18n key | default | 
| struts.date.format | if one is not found DateFormat.MEDIUM format will be used | 
Examples
  
  <s:date name="person.birthday" format="dd/MM/yyyy" />
  <s:date name="person.birthday" format="%{getText('some.i18n.key')}" />
  <s:date name="person.birthday" nice="true" />
  <s:date name="person.birthday" />
  
 
 Date- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringProperty name to fall back when no format is specifiedstatic final StringProperty name that defines the days notation (default: {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours})static final StringProperty name that defines the future notation (default: in {0})static final StringProperty name that defines the hours notation (default: {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1>, {1} minutes})static final StringProperty name that defines the minutes notation (default: {0,choice,1#one minute|1<{0} minutes})static final StringProperty name that defines the past notation (default: {0} ago)static final StringProperty name that defines the seconds notation (default: in instant)static final StringProperty name that defines the years notation (default: {0,choice,1#one year|1<{0} years}{1,choice,0#|1#, one day|1>, {1} days})Fields inherited from class org.apache.struts2.components.ContextBeanvarFields inherited from class org.apache.struts2.components.ComponentactionMapper, attributes, COMPONENT_STACK, devMode, escapeHtmlBody, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanCallback for the end tag of this component.formatTime(TextProvider tp, ZonedDateTime date) Calculates the difference in time from now to the given date, and outputs it nicely.getName()booleanisNice()voidsetDateFormatter(DateFormatter dateFormatter) An instance ofDateFormattervoidvoidvoidsetNice(boolean nice) voidsetTimezone(String timezone) Methods inherited from class org.apache.struts2.components.ContextBeangetVar, putInContext, setVarMethods inherited from class org.apache.struts2.components.ComponentaddAllAttributes, addParameter, completeExpression, copyAttributes, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getAttributes, getComponentStack, getNamespace, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpression, toString, usesBody
- 
Field Details- 
DATETAG_PROPERTYProperty name to fall back when no format is specified- See Also:
 
- 
DATETAG_PROPERTY_PASTProperty name that defines the past notation (default: {0} ago)- See Also:
 
- 
DATETAG_PROPERTY_FUTUREProperty name that defines the future notation (default: in {0})- See Also:
 
- 
DATETAG_PROPERTY_SECONDSProperty name that defines the seconds notation (default: in instant)- See Also:
 
- 
DATETAG_PROPERTY_MINUTESProperty name that defines the minutes notation (default: {0,choice,1#one minute|1<{0} minutes})- See Also:
 
- 
DATETAG_PROPERTY_HOURSProperty name that defines the hours notation (default: {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1>, {1} minutes})- See Also:
 
- 
DATETAG_PROPERTY_DAYSProperty name that defines the days notation (default: {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours})- See Also:
 
- 
DATETAG_PROPERTY_YEARSProperty name that defines the years notation (default: {0,choice,1#one year|1<{0} years}{1,choice,0#|1#, one day|1>, {1} days})- See Also:
 
 
- 
- 
Constructor Details- 
Date
 
- 
- 
Method Details- 
setDateFormatterAn instance ofDateFormatter
- 
formatTimeCalculates the difference in time from now to the given date, and outputs it nicely.
 An example:
 Now = 2006/03/12 13:38:00, date = 2006/03/12 15:50:00 will output "in 1 hour, 12 minutes".- Parameters:
- tp- text provider
- date- the date
- Returns:
- the date nicely
 
- 
endDescription copied from class:ComponentCallback for the end tag of this component. Should the body be evaluated again?
 NOTE: will pop component stack.
- 
setFormat
- 
setNicepublic void setNice(boolean nice) 
- 
setTimezone
- 
getName- Returns:
- the name.
 
- 
setName
- 
getFormat- Returns:
- the format.
 
- 
isNicepublic boolean isNice()- Returns:
- the nice.
 
- 
getTimezone- Returns:
- the timezone.
 
 
-