How to set date format for apex:outputText?

How to set date format for apex:outputText?

For MM/DD/YYYY format:

<apex:outputText value="{0,date,MM/dd/yyyy}" >  
    <apex:param value="{!dateField}"/>  
</apex:outputText> 

Sample Code:

Visualforce page:

<apex:page controller="Sample" >  
    <apex:form > 
         <apex:outputText value="{0,date,dd'/'MM'/'yyyy}" >  
             <apex:param value="{!temp}"/>
         </apex:outputText>
    </apex:form> 
</apex:page>  

Apex Controller:

public with Sharing class Sample {  
      
    public Date gettemp() {  
  
        Date d = date.ValueOf('2013-12-10');  
        return d;  
  
    }  
  
    public List < Member__c > mem {get;set;}      
         
    public sample() {}  
  
} 

Output:

Note: Make sure ‘MM’ is alone in capital letters.

Leave a Reply