Wednesday, April 4, 2012

How to format a date in VisualForce?

APEX Class:

public List<Attachment> getCaseAttachmentList(){
  if(caseId != null && caseId != '') {
 string attachCaseQry = 'Select Id, Name, Body, CreatedDate From Attachment where ParentId = \''+caseId+ '\'';
 caseAttachmentList = (List<Attachment>)Database.query(attachCaseQry);
 system.debug('Attachment Result:' + caseAttachmentList);
 
  }
  return caseAttachmentList;
}

VisualForce Page:

<apex:repeat value="{!CaseAttachmentList}" var="attachmentCaseObj"> 
<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
<apex:param value="{!attachmentCaseObj.CreatedDate}" /> 
</apex:outputText>
<br />
</apex:repeat>

Output:
03/30/2012
04/02/2012
04/01/2012

No comments:

Post a Comment