layout: default title: date tag parent: title: Tag Reference url: tag-reference.html

date

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

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.

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

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 keydefault
struts.date.formatif one is not found DateFormat.MEDIUM format will be used

{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/site/resources/tags/date-description.html %}

Attributes

{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/site/resources/tags/date-attributes.html %}

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" />