Formatting DATES inside VisualForce - El Toro - Find articles about Visualforce, Apex, Force.com and Salesforce in general

Print Preview

Formatting DATES inside VisualForce

This displays a field of type date or Datetime using the format MM-dd-yyy

<apex:outputText value="{0, date, MM-dd-yyyy}">
	<apex:Param value="{!Objectname.FieldNameOfTypeDate }" />
</apex:OutputText>

You may also use something like this

<apex:outputText value="{0, date, {!DateFormat}}">
	<apex:Param value={!Objectname.FieldNameOfTypeDate } />
</apex:OutputText>

Where you provide teh format in Apex, this is useful if different users view the date/times in different formats.

public String getDateFormat() {
    return 'MMMM dd yyyy';
}

The full reference as to what can be used on the third parameter can be found here: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

comments powered by Disqus

© El Toro . IT @ 2013
Andrés Pérez