Visualforce Locale specific date format

The easiest way to do this might be to utilise the 'named' date formats that are available, for example, short and long:

<apex:outputText value="{0,date,short}">
    <apex:param value="{!Opportunity.CloseDate}" /> 
</apex:outputText>

<apex:outputText value="{0,date,long}">
    <apex:param value="{!Opportunity.CloseDate}" /> 
</apex:outputText>

BUG ALERT

While official documentation hints that message formats respect locale, currently the named messages formats (short, medium, and long) always output in US date format (month then day) or possibly the locale of your instance. A support request was logged and R&D replies that this won't work and will never work

This is "working as designed." OutputText has always been un-respectful of user locale. For user locale specific data you need to use OutputField. While addressing this may fix the issue for you the rest of our customers have been using it this way from the begin. While MessageFormat.java does talking about using locale, it uses the locale of the localhost only, not the running users.


If you can use the Salesforce outputField component instead of outputText, it will automatically adjust to the locale of the context user.

If you have a custom controller or extension on your page, the instance method format() on the Date primitive will return the date as a string formatted in the user's locale.

Opportunity.CloseDate.format()

Tags:

Visualforce