My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians


vineri, 13 noiembrie 2015

[OmniFaces utilities 2.0] Format the given date in the given pattern with system default/provided timezone

[OmniFaces utilities] The formatDate() function formats the given date in the given pattern with system default/given timezone. This is useful when you want to format dates in for example the title attribute of an UI component, or the itemLabel attribute of select item, or wherever you can't use the <f:convertDateTime> tag. The format locale will be set to the one as obtained by Faces#getLocale().


The of:formatDate() uses the default timezone (TimeZone.getDefault()). Below, you can see several examples:

public class DateBean {
 private Date date = new Date();
 // getters & setters

dd-MM-yyyy / #{of:formatDate(, "dd-MM-yyyy")}
dd/MM/yy / #{of:formatDate(, "dd/MM/yy")}
dd-MM-yy:HH:mm:SS / #{of:formatDate(, "dd-MM-yy:HH:mm:SS")}
dd-MM-yy:HH:mm:SS Z / #{of:formatDate(, "dd-MM-yy:HH:mm:SS Z")}


dd-MM-yyyy / 14-11-2015
dd/MM/yy / 14/11/15
dd-MM-yy:HH:mm:SS / 14-11-15:08:12:604
dd-MM-yy:HH:mm:SS Z / 14-11-15:08:12:604 +0200

If you need to indicate the timezone also, then use of:formatDateWithTimezone(). Here it is two examples:

public class DateBean {
 private Date date = new Date();
 private TimeZone tm = TimeZone.getTimeZone("America/Los_Angeles");

 // getters & setters

yyyy-MM-dd HH:mm:ss, GMT / #{of:formatDateWithTimezone(, 'yyyy-MM-dd HH:mm:ss', 'GMT')} <br/>      
yyyy-MM-dd HH:mm:ss, America/Los_Angeles / #{of:formatDateWithTimezone(, 'yyyy-MM-dd HH:mm:ss',}


yyyy-MM-dd HH:mm:ss, GMT / 2015-11-14 06:14:29
yyyy-MM-dd HH:mm:ss, America/Los_Angeles / 2015-11-13 22:14:29

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors