function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sgoremasgorema 

Date formatting in Visual Force

I have a VF page that I am rendering as a PDF doc. This is our actual contract and so the contact start and end dates are displayed on the document. The problem that I just came across is that these start dates and end dates are rendering on the pdf in the locale of the end user who generates the doc. This has become confusing for our centrally located Order Processing group here in the States b/c they are reading the UK date format dd-mm-yyyy in the US format. How can I get the dates to always display in the English(US) locale. Currently I simply diosplaying it using the apex:outputfield tag:
 
Code:
<td><apex:outputField value="{!SFDC_520_Quote__c.Subscription_Start_Date__c}"/></td>

 
thanks!
Ron HessRon Hess
you could format a date in any locale using a controller and a getter method that would always return the date as a string in the desired locale.

you would then display this using outputText instead of outputfield.

Mark YoungMark Young
Wrap the field in a getter (either in the page controller, or return an object wrapper).  Then use datetime.format('MM/dd/yyyy');
 
Or if using a date:
Code:
public String getFormattedStartDate()
{
    Date d = getSFDC_520_Quote__c().Subscription_start_date__c;
    if (d != null)
    {
        return DateTime.newInstance(d.year(), d.month(), d.day()).format('MM/dd/yyyy');
    }
    else
    {
        return '';
    }
}