Name

<fmt:formatDate>

Synopsis

The <fmt:formatDate> action formats a date and time value according to locale specific rules. A custom pattern can be specified or locale-dependent default patterns for one or both of the date and the time portion can be selected.

The locale is taken from the locale configuration setting or the locale from the localization context setting, or if none of these are set, determined as the best match for the user preferences (Accept-Language request header).

If the value to format is null or an empty string, no output is generated, and if a variable to hold the output is specified, it’s removed.

Syntax

<fmt:formatDate value="dateAndTime" 
  [pattern="pattern" |
    [type="time|date|both"]
    [dateStyle="default|short|medium|long|full"]
    [timeStyle="default|short|medium|long|full"]]
  [timeZone="timeZone"]
  [var="var" [scope="page|request|session|application"]] />

Attributes

Attribute name

Java type

Dynamic value accepted

Description

value
java.util.Date

Yes

The date and time to format.

pattern
String

Yes

A custom pattern in the form accepted by java.text.SimpleDateFormat (see the next table).

type
String

Yes

Which portions to format.

dateStyle
String

Yes

One of the predefined locale-dependent date patterns.

timeStyle
String

Yes

One of the predefined locale-dependent time patterns.

timeZone
String or java.util.TimeZone

Yes

The time zone to use instead of the default.

var
String

No

The variable name. The type is String.

scope
String

No

The ...

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.