Save This Page
Home » struts- » org.apache » struts2 » components » [javadoc | source]
public class: Date [javadoc | source]
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 '' 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.

Configurable attributes are :-

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 {0} ago in {0} an instant {0,choice,1#one minute|1<{0} minutes} {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1<, {1} minutes} {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours} {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 if one is not found DateFormat.MEDIUM format will be used


 <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" />
Field Summary
public static final  String DATETAG_PROPERTY    Property name to fall back when no format is specified 
public static final  String DATETAG_PROPERTY_PAST    Property name that defines the past notation (default: {0} ago) 
public static final  String DATETAG_PROPERTY_FUTURE    Property name that defines the future notation (default: in {0}) 
public static final  String DATETAG_PROPERTY_SECONDS    Property name that defines the seconds notation (default: in instant) 
public static final  String DATETAG_PROPERTY_MINUTES    Property name that defines the minutes notation (default: {0,choice,1#one minute|1<{0} minutes}) 
public static final  String DATETAG_PROPERTY_HOURS    Property name that defines the hours notation (default: {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1<, {1} minutes}) 
public static final  String DATETAG_PROPERTY_DAYS    Property name that defines the days notation (default: {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours}) 
public static final  String DATETAG_PROPERTY_YEARS    Property 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 org.apache.struts2.components.ContextBean:
Fields inherited from org.apache.struts2.components.Component:
COMPONENT_STACK,  stack,  parameters,  actionMapper,  throwExceptionOnELFailure
 public Date(ValueStack stack) 
Method from org.apache.struts2.components.Date Summary:
end,   formatTime,   getFormat,   getName,   isNice,   setFormat,   setName,   setNice
Methods from org.apache.struts2.components.ContextBean:
getVar,   putInContext,   setId,   setVar
Methods from org.apache.struts2.components.Component:
addAllParameters,   addParameter,   altSyntax,   altSyntax,   completeExpressionIfAltSyntax,   copyParams,   determineActionURL,   determineNamespace,   end,   end,   fieldError,   findAncestor,   findString,   findString,   findStringIfAltSyntax,   findValue,   findValue,   findValue,   getComponentStack,   getParameters,   getStack,   popComponentStack,   setActionMapper,   setThrowExceptionsOnELFailure,   start,   stripExpressionIfAltSyntax,   stripExpressionIfAltSyntax,   toString,   usesBody
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.struts2.components.Date Detail:
 public boolean end(Writer writer,
    String body) 
 public String formatTime(TextProvider tp,
    Date date) 
    Calculates 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".

 public String getFormat() 
 public String getName() 
 public boolean isNice() 
 public  void setFormat(String format) 
 public  void setName(String name) 
 public  void setNice(boolean nice)