Friday, December 9, 2016

Date field Formatting on VF page

If you have to format Date fields directly on VF page, then you can use below code snippets to achieve this.

<apex:page standardController="Opportunity">
    <!--display=10/25-->
    <apex:outputlabel value="Opportunity Close date (MM/dd):" />
    <apex:outputText value="{0,date,MM/dd}">
        <apex:param value="{!opportunity.CloseDate}"  />                              
    </apex:outputText>
    <br/>

    <!--display=October 25-->
    <apex:outputlabel value="Opportunity Close date (MMMM dd): " />
    <apex:outputText value="{0,date,MMMM dd}">
        <apex:param value="{!opportunity.CloseDate}"  />  
    </apex:outputText>
    <br/>
    
    <!--display= display=25 October-->
    <apex:outputlabel value="Opportunity Close date (dd MMMM): " />
    <apex:outputText value="{0,date,dd MMMM}">
        <apex:param value="{!opportunity.CloseDate}"  />                                   
    </apex:outputText>
    <br/>
    
    <!--  display=DD/MM-->
    <apex:outputlabel value="Opportunity Close date (DD/MM): " />
    {!Day(opportunity.CloseDate)}/{!Month(opportunity.CloseDate)}                           
</apex:page>


Output on VF Page:

08/06 
August 06 
06 August 
6/8







Refer Below Links for Salesforce Interview Questions





No comments:

Post a Comment