|
12. JSF Core Tag Reference
Documentation
>
JSF
>
JSF Tag Reference
>
JSF Core Tag Library
>
f:convertDateTime
f:convertDateTime |
|
The ConvertDateTime tag is useful for converting a date into a
human-readable format and supports a range of formatting options. You can use
this tag to control the style and appearance of a date on your JSF page. The
ConvertDateTime tag applies to the date value of the component associated with
the enclosing tag. The body content of this tag must be empty.
JSF Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<f:view>
<h:outputText value="#{dateBean.today}">
<f:convertDateTime dateStyle="full" timeZone="EST" type="date" />
</h:outputText>
</f:view>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.
Java Code
package com.mycompany;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
/**
* JSF2 managed bean for date handling.
*/
@ManagedBean
@RequestScoped
public class DateBean {
public Date getToday() {
return new Date();
}
}
HTML Output
Sunday, January 1, 2006
|
Tag Attributes
| binding |
Expression
|
| |
|
The value-binding expression linking this component tag to a backing bean property.
|
| dateStyle |
Enumerated
|
| |
This attribute sets a predefined formatting style which determines how a
date string is to be formatted. It only applies the type attribute is
"date" or "both".
Valid values for this attribute are:
|
Date Style
|
Example
|
|
default
|
Jan 1, 2006 1:20:45 PM
|
|
short
|
1/1/06 1:20:45 PM
|
|
medium
|
Jan 1, 2006 1:20:45 PM
|
|
long
|
January 1, 2006 1:20:45 PM
|
|
full
|
Sunday, January 1, 2006 1:20:45 PM
|
The default value is "default".
This attribute accepts the following values:
-
default
(default)
-
full
-
long
-
medium
-
short
|
| for |
Text
|
| |
|
If present, this attribute refers to the value of one of the exposed attached objects within the composite component inside of which this tag is nested.
|
| locale |
Enumerated
|
| |
|
The locale attribute sets the language, country, and variant for formatting locale-sensitive data such as numbers and dates. If not specified, the Locale returned by FacesContext. getViewRoot(). getLocale() will be used. Valid expressions must evaluate to a java. util. Locale.
|
| pattern |
Enumerated
|
| |
The pattern attribute sets the custom formatting pattern which
determines how the date/time string should be formatted and parsed.
|
Pattern
|
Result
|
|
yyyy. MM. dd 'at' HH:mm:ss z
|
2006. 01. 01 at 10:05:30 EST
|
|
EEE, MMM d, ''yy
|
Sun, Jan 1, '06
|
|
h:mm a
|
10:05 AM
|
|
hh 'o''clock' a, zzzz
|
10 o'clock AM, Eastern Standard Time
|
|
EEE, d MMM yyyy HH:mm:ss Z
|
Sun, 1 Jan 2006 10:05:30 -0500
|
For more examples of date formatting patterns, please see the Java API
documentation for java. text. SimpleDateFormat.
This attribute accepts the following values:
-
-
EEE, MMM d, ''yy
-
EEE, d MMM yyyy HH:mm:ss Z
-
MM/dd/yy
-
hh 'o''clock' a, zzzz
-
yyyy.MM.dd 'at' HH:mm:ss z
|
| timeStyle |
Enumerated
|
| |
The timeStyle attribute sets a predefined formatting style which determines how a time string is to be formatted and parsed. Applied only if the type attribute is "time" or "both".
Valid values are:
| Date Style |
Example |
| default |
Jan 1, 2006 10:05:30 AM
|
| short |
1/1/06 10:05:30 AM
|
| medium |
Jan 1, 2006 10:05:30 AM
|
| long |
January 1, 2006 10:05:30 AM
|
| full |
Sunday, January 1, 2006 10:05:30 AM
|
The default value is "default".
This attribute accepts the following values:
-
default
-
full
-
long
-
medium
-
short
|
| timeZone |
Enumerated
|
| |
|
This attribute sets the time zone for which to interpret date/time information. The value must be either a value-binding expression that evaluates to a java. util. TimeZone instance, or a String that is a timezone ID as per the Java API documentation for java. util. TimeZone. getTimeZone().
|
| type |
Enumerated
|
| |
|
This attributes specifies what type of information the string to be formatted or parsed will contain. The valid values for this attribute are "date", "time", and "both". The default value is "date".
This attribute accepts the following values:
|
|
|
|
|
|