How to format a date in VisualForce?

前端 未结 2 1678
一向
一向 2021-02-05 03:27

In Salesforce, if I\'m binding a date into a VisualForce page, how do I apply custom formatting to it?

Example:



        
相关标签:
2条回答
  • 2021-02-05 04:01
    <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
        <apex:param value="{!contact.Birthdate}" /> 
    </apex:outputText>
    

    link to full doc: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputText.htm

    0 讨论(0)
  • 2021-02-05 04:15

    The answer seems to depend on context. I have one VF page which pre-populates the Subject line of a task with the value of NOW(). To record it with the user's Locale settings, I included methods in the controller to format date and datetime fields, along these lines:

      Datetime myDT = Datetime.now(); 
      String myDate = myDT.format();
    

    But just now in another VF page where I'm merely displaying a datetime field, I confirmed that SFDC handled formatting based on the user's Locale setting. That was in this context, where cm.CampaignMembers is a variable from the controller:

        <apex:column>
          <apex:pageBlockTable value="{!cm.CampaignMembers}" var="cmp" >
            <apex:column headerValue="" value="{!cmp.Campaign.Name}" />
            <apex:column headerValue="" value="{!cmp.Status}"  />
            <apex:column headerValue="" value="{!cmp.FirstRespondedDate}" />
            <apex:column headervalue="" value="{!cmp.CreatedDate}"  />
          </apex:pageBlockTable>
        </apex:column>
    
    0 讨论(0)
提交回复
热议问题