Play Games

Search This Blog

Thursday, November 19, 2015

Format Date in Visualforce Page

Apex Class:
public class FormatDate {
    public date startDate {get;set;}
    public FormatDate () {
        startDate = system.TODAY();
    }
}
Visualforce Page:
<apex:page controller="FormatDate">
<apex:pageBlock>
    Date in "MMM-YYYY" Format    (Eg:Nov-2015)<br/>
    <apex:outputText value="{0,date,MMM-YYYY}">
        <apex:param value="{!startDate}" />
    </apex:outputText><br/><br/>
    Date in "DD/MM/YY" Format    (Eg:19/11/15)<br/>
    <apex:outputText value="{0,date,dd/MM/yy}">
        <apex:param value="{!startDate}" />
    </apex:outputText><br/><br/>
    Date in "DD/MMM/YYYY" Format    (Eg:19/Nov/2015)<br/>
    <apex:outputText value="{0,date,dd/MMM/yyyy}">
        <apex:param value="{!startDate}" />
    </apex:outputText><br/><br/>
    Date in "DD-MMM-YYYY" Format    (Eg:19-Nov-2015)<br/>
    <apex:outputText value="{0,date,dd-MMM-yyyy}">
        <apex:param value="{!startDate}" />
    </apex:outputText>
</apex:pageBlock>
</apex:page>
Important Note: In the <apex:outputText>  tag ,value attribute value should contain   small letter "dd" not Capital letter "DD" .For eg: value="{0,date,dd-MMM-yyyy}"
Output:

No comments:

Post a Comment