Friday, December 20, 2013

Date Format with <p:calendar />

There are 2 ways to define date format for <p:calendar />
1. locale
2. pattern

Option 1: locale

Simply pass in the desired locale.
<p:calendar
    value="#{bean.dateValue}"
    locale="en_US" />

available locales could be found at LocalePlanet.


Option 2: pattern


passed in desired date pattern
<p:calendar
    value="#{bean.dateValue}"
    pattern="dd/MM/yyyy" />

some sample java date patterns
PatternOutput
dd/MM/yyyy20/12/2013
dd/MM/yy20/12/13
d/M/yyyy20/12/2013
d/M/yy20/12/13
dd/MMM/yyyy20/Dec/2013
dd-MM-yyyy20-12-2013
MMM d, yyyyDec 20, 2013
yyyy/MM/dd2013/12/20
EEE, dd MMM yyyyFri, 20 Dec 2013
EEE, dd/MMM/yyyyFri, 20/Dec/2013

more java date pattern could be tested at Online SimpleDateFormat Test.


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...