Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > date

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

i18n keydefault
struts.date.format.past{0} ago
struts.date.format.futurein {0}
struts.date.format.secondsan instant
struts.date.format.minutes{0,choice,1#one minute|1<_0 minutes="minutes" td="td">
struts.date.format.hours{0,choice,1#one hour|1<_0 hours1choice01="hours1choice01" one="one" minute1="minute1" _1="_1" minutes="minutes" td="td">
struts.date.format.days{0,choice,1#one day|1<_0 days1choice01="days1choice01" one="one" hour1="hour1" _1="_1" hours="hours" td="td">
struts.date.format.years{0,choice,1#one year|1<_0 years1choice01="years1choice01" one="one" day1="day1" _1="_1" days="days" td="td">

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

Parameters

Dynamic Attributes Allowed:

false
 

Name

Required

Default

Evaluated

Type

Description

formatfalsefalseStringDate or DateTime format pattern
idfalsefalseStringDeprecated. Use 'var' instead
nametruefalseStringThe date value to format
nicefalsefalsefalseBooleanWhether to print out the date nicely
timezonefalsefalseStringThe specific timezone in which to format the date
varfalsefalseStringName used to reference the value pushed into the Value Stack

Examples