Format date for a Locale

A very common use case related to localization is that, formatting the date specific to a user-selected locale.
Following code snippet will help you to identify the default pattern corresponding to a locale.
String pattern =
((SimpleDateFormat)DateFormat.getDateTimeInstance(SimpleDateFormat.FULL,
SimpleDateFormat.LONG,
locale)).toPattern();


Your jsf page snippet may look like:
  <af:inputDate label="Date:" id="id1" value="#{viewScope.TestBean.date}"
                      binding="#{viewScope.TestBean.inputDate}"
                      partialTriggers="soc1">
          <af:convertDateTime type="both"
                              timeZone="#{viewScope.TestBean.timeZone}"
                              locale="#{viewScope.TestBean.locale}"
                              pattern="#{viewScope.TestBean.pattern}"
                             />
        </af:inputDate>
You can download the sample workspace from here.

Comments

  1. Thanks this was helpful.

    ReplyDelete
  2. Hi Jobinesh,

    Thanks for the Article.
    Can we specify the pattern at global level.
    I have figured it out that we can specify the timezone in trinidad-config to have effect on globally.

    Any hints appreciated.

    Thanks.

    ReplyDelete

Post a Comment

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.