views:

237

answers:

1

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

Example:

<apex:page standardController="Contact">
  <apex:pageBlock title="Test">
      <p>{!contact.Birthdate}</p>
  </apex:pageBlock>                   
  <apex:detail relatedList="false" />
</apex:page> 

This will output a date in the default format:

Thu Jul 01 09:10:23 GMT 2009

How do I get it (for example) into dd/mm/yyyy format, like this:

01/07/2009

(Hopefully this is a fairly easy question, but to get the Salesforce community going on here I figure we need a few easy questions.)

+2  A: 
<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
    <apex:param value="{!contact.Birthdate}" /> 
</apex:outputText>
Ryan Guest
Using this approach you can use the full JAVA date formatting classes to format: datetimes, numbers and currency.
Daveo

related questions